home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / Ang261Lib.lha / src / misc1.c < prev    next >
C/C++ Source or Header  |  1994-10-22  |  149KB  |  6,026 lines

  1. /*
  2.  * Misc1.c: misc utility and initialization code, magic objects code 
  3.  *
  4.  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke 
  5.  *
  6.  * This software may be copied and distributed for educational, research, and
  7.  * not for profit purposes provided that this copyright and statement are
  8.  * included in all such copies. 
  9.  */
  10.  
  11. #ifndef FSCALE
  12. #define FSCALE (1<<8)
  13. #endif
  14.  
  15. #if defined(Pyramid) || defined(NeXT) || defined(sun) || \
  16. defined(NCR3K) || defined(linux) || defined(ibm032) || defined (__osf__)
  17. #include <sys/time.h>
  18. #else
  19. #include <time.h>
  20. #endif
  21.  
  22. #if !defined(GEMDOS) && !defined(MAC)
  23. #ifndef VMS
  24. #include <sys/types.h>
  25. #else
  26. #include <types.h>
  27. #endif
  28. #endif
  29.  
  30. #include <stdio.h>
  31. #include "constant.h"
  32. #include "monster.h"
  33. #include "config.h"
  34. #include "types.h"
  35. #include "externs.h"
  36.  
  37. #ifdef USG
  38. #ifndef ATARIST_MWC
  39. #include <string.h>
  40. #else
  41. #include "string.h"
  42. #endif
  43. #else
  44. #include <strings.h>
  45. #endif
  46.  
  47. typedef struct statstime {
  48.     int                 cp_time[4];
  49.     int                 dk_xfer[4];
  50.     unsigned int        v_pgpgin;
  51.     unsigned int        v_pgpgout;
  52.     unsigned int        v_pswpin;
  53.     unsigned int        v_pswpout;
  54.     unsigned int        v_intr;
  55.     int                 if_ipackets;
  56.     int                 if_ierrors;
  57.     int                 if_opackets;
  58.     int                 if_oerrors;
  59.     int                 if_collisions;
  60.     unsigned int        v_swtch;
  61.     long                avenrun[3];
  62.     struct timeval      boottime;
  63.     struct timeval      curtime;
  64. } statstime;
  65.  
  66.  
  67. /* Lets do all prototypes correctly.... -CWS */
  68. #ifndef NO_LINT_ARGS
  69. #ifdef __STDC__
  70. static int   test_place(int, int);
  71. static char *cap(char *);
  72. static void  magic_ammo(inven_type *, int, int, int, int, int);
  73. #else
  74. static int   test_place();
  75. static char *cap();
  76. static void  magic_ammo();
  77. #endif
  78. static void compact_objects();
  79. #endif
  80.  
  81. extern int peek;
  82. extern int rating;
  83.  
  84.  
  85. /* gets a new random seed for the random number generator */
  86. void
  87. init_seeds()
  88. {
  89.     old_state = (char *) malloc(256); /* excellent R.N.G. */
  90.     dummy_state = (char *) malloc(8); /* so-so R.N.G., but who cares? -CFT */
  91.     
  92.     /* if malloc choked on 264 bytes, we're dead anyways */
  93.     if (!old_state || !dummy_state) {
  94.     puts("\nError initializing; unable to malloc space for RNG arrays...\n");
  95.     exit(2);
  96.     }
  97.     
  98.     /* is 'unix' a std define for unix system?  I thought UNIX is more common?
  99.        This may need to be changed.  It's fine for PCs, anyways... -CFT */
  100. #ifdef unix
  101.     /* Grab a random seed from the clock & PID... */
  102.     (void) initstate(time(NULL), dummy_state, 8);
  103.     (void) initstate(((getpid() << 1) * (time(NULL) >> 3)), old_state, 256);
  104. #else
  105.     /* ...else just grab a random seed from the clock. -CWS */
  106.     (void) initstate(time(NULL), dummy_state, 8);
  107.     (void) initstate(random(), old_state, 256);
  108. #endif /* unix */
  109.     town_seed = random();
  110.     randes_seed = random();
  111. }
  112.  
  113. /* change to different random number generator state */
  114. void 
  115. set_seed(seed)
  116. int32u seed;
  117. {
  118.     setstate(dummy_state);
  119.     srandom((seed % 2147483646L) + 1);    /* necessary to keep the town/desc's */
  120. }                                       /* the same (legacy from rnd.c) -CWS */
  121.  
  122.  
  123. /* restore the normal random generator state */
  124. void 
  125. reset_seed()
  126. {
  127.     (void)setstate(old_state);
  128. }
  129.  
  130.  
  131. #if !defined(time_t)
  132. #define time_t long
  133. #endif
  134.  
  135. /* Check the day-time strings to see if open        -RAK-     */
  136. int 
  137. check_time()
  138. {
  139. #ifdef CHECKHOURS
  140.     time_t              c;
  141.     register struct tm *tp;
  142. #ifndef __MINT__
  143.     struct statstime    st;
  144. #endif
  145.  
  146.     c = time((time_t *)0);
  147.     tp = localtime(&c);
  148.     if (days[tp->tm_wday][tp->tm_hour + 4] != 'X') {
  149.     return FALSE;
  150.     }
  151. #if !(defined(__MINT__) || defined(NCR3K) || defined(linux) \
  152. || defined(__386BSD__) || defined (__osf__))
  153.  else {
  154.     if (!rstat("localhost", &st)) {
  155.         if (((int)((double)st.avenrun[2] / (double)FSCALE)) >= (int)LOAD)
  156.         return FALSE;
  157.     }
  158.     }
  159. #endif /* MINT, etc */
  160. #endif /* CHECKHOURS - [cjh] */
  161.     return TRUE;
  162. }
  163.  
  164. #ifdef RI
  165. /* Generates a random integer x where 1<=X<=MAXVAL    -RAK-     */
  166. int 
  167. randint(maxval)
  168. int maxval;
  169. {
  170.     register long randval;
  171.  
  172.     if (maxval < 1)
  173.     return 1;
  174.     randval = random();
  175.     return ((randval % maxval) + 1);
  176. }
  177.  
  178. #endif
  179.  
  180. /* Generates a random integer number of NORMAL distribution -RAK- */
  181. int 
  182. randnor(mean, stand)
  183. int mean, stand;
  184. {
  185.     register int tmp, offset, low, iindex, high;
  186.  
  187.     tmp = randint(MAX_SHORT);
  188.  
  189. /* off scale, assign random value between 4 and 5 times SD */
  190.     if (tmp == MAX_SHORT) {
  191.     offset = 4 * stand + randint(stand);
  192.  
  193.     /* one half are negative */
  194.     if (randint(2) == 1)
  195.         offset = (-offset);
  196.  
  197.     return (mean + offset);
  198.     }
  199. /* binary search normal normal_table to get index that matches tmp */
  200. /* this takes up to 8 iterations */
  201.     low = 0;
  202.     iindex = NORMAL_TABLE_SIZE >> 1;
  203.     high = NORMAL_TABLE_SIZE;
  204.     while (TRUE) {
  205.     if ((normal_table[iindex] == tmp) || (high == (low + 1)))
  206.         break;
  207.     if (normal_table[iindex] > tmp) {
  208.         high = iindex;
  209.         iindex = low + ((iindex - low) >> 1);
  210.     } else {
  211.         low = iindex;
  212.         iindex = iindex + ((high - iindex) >> 1);
  213.     }
  214.     }
  215.  
  216. /* might end up one below target, check that here */
  217.     if (normal_table[iindex] < tmp)
  218.     iindex = iindex + 1;
  219.  
  220. /* normal_table is based on SD of 64, so adjust the index value here, round
  221.  * the half way case up 
  222.  */
  223.     offset = ((stand * iindex) + (NORMAL_TABLE_SD >> 1)) / NORMAL_TABLE_SD;
  224.  
  225. /* one half should be negative */
  226.     if (randint(2) == 1)
  227.     offset = (-offset);
  228.  
  229.     return (mean + offset);
  230. }
  231.  
  232.  
  233. /* Returns position of first set bit            -RAK-     */
  234. /* and clears that bit */
  235. int 
  236. bit_pos(test)
  237. int32u *test;
  238. {
  239.     register int    i;
  240.     register int32u mask = 0x1L;
  241.  
  242.     for (i = 0; i < sizeof(*test) * 8; i++) {
  243.     if (*test & mask) {
  244.         *test &= ~mask;
  245.         return (i);
  246.     }
  247.     mask <<= 0x1L;
  248.     }
  249.  
  250. /* no one bits found */
  251.     return (-1);
  252. }
  253.  
  254.  
  255. /* Calculates current boundaries                -RAK-     */
  256. void 
  257. panel_bounds()
  258. {
  259.     panel_row_min = panel_row * (SCREEN_HEIGHT / 2);
  260.     panel_row_max = panel_row_min + SCREEN_HEIGHT - 1;
  261.     panel_row_prt = panel_row_min - 1;
  262.     panel_col_min = panel_col * (SCREEN_WIDTH / 2);
  263.     panel_col_max = panel_col_min + SCREEN_WIDTH - 1;
  264.     panel_col_prt = panel_col_min - 13;
  265. }
  266.  
  267.  
  268. /* Given an row (y) and col (x), this routine detects  -RAK-     */
  269. /*
  270.  * when a move off the screen has occurred and figures new borders. Force
  271.  * forcses the panel bounds to be recalculated, useful for 'W'here. 
  272.  */
  273. int 
  274. get_panel(y, x, force)
  275. int y, x, force;
  276. {
  277.     register int prow, pcol;
  278.     register int panel;
  279.  
  280.     prow = panel_row;
  281.     pcol = panel_col;
  282.     if (force || (y < panel_row_min + 2) || (y > panel_row_max - 2)) {
  283.     prow = ((y - SCREEN_HEIGHT / 4) / (SCREEN_HEIGHT / 2));
  284.     if (prow > max_panel_rows)
  285.         prow = max_panel_rows;
  286.     else if (prow < 0)
  287.         prow = 0;
  288.     }
  289.     if (force || (x < panel_col_min + 3) || (x > panel_col_max - 3)) {
  290.     pcol = ((x - SCREEN_WIDTH / 4) / (SCREEN_WIDTH / 2));
  291.     if (pcol > max_panel_cols)
  292.         pcol = max_panel_cols;
  293.     else if (pcol < 0)
  294.         pcol = 0;
  295.     }
  296.     if ((prow != panel_row) || (pcol != panel_col)) {
  297.     panel_row = prow;
  298.     panel_col = pcol;
  299.     panel_bounds();
  300.     panel = TRUE;
  301.     /* stop movement if any */
  302.     if (find_bound)
  303.         end_find();
  304.     } else
  305.     panel = FALSE;
  306.     return (panel);
  307. }
  308.  
  309.  
  310. /* Distance between two points                -RAK-     */
  311. int 
  312. distance(y1, x1, y2, x2)
  313. int y1, x1, y2, x2;
  314. {
  315.     register int dy, dx;
  316.  
  317.     dy = y1 - y2;
  318.     if (dy < 0)
  319.     dy = (-dy);
  320.     dx = x1 - x2;
  321.     if (dx < 0)
  322.     dx = (-dx);
  323.  
  324.     return ((((dy + dx) << 1) - (dy > dx ? dx : dy)) >> 1);
  325. }
  326.  
  327.  
  328. /* Checks points north, south, east, and west for a wall -RAK-     */
  329. /*
  330.  * note that y,x is always in_bounds(), i.e. 0 < y < cur_height-1, and 0 < x
  331.  * < cur_width-1     
  332.  */
  333. int 
  334. next_to_walls(y, x)
  335. register int y, x;
  336. {
  337.     register int        i;
  338.     register cave_type *c_ptr;
  339.  
  340.     i = 0;
  341.     c_ptr = &cave[y - 1][x];
  342.     if (c_ptr->fval >= MIN_CAVE_WALL)
  343.     i++;
  344.     c_ptr = &cave[y + 1][x];
  345.     if (c_ptr->fval >= MIN_CAVE_WALL)
  346.     i++;
  347.     c_ptr = &cave[y][x - 1];
  348.     if (c_ptr->fval >= MIN_CAVE_WALL)
  349.     i++;
  350.     c_ptr = &cave[y][x + 1];
  351.     if (c_ptr->fval >= MIN_CAVE_WALL)
  352.     i++;
  353.  
  354.     return (i);
  355. }
  356.  
  357.  
  358. /* Checks all adjacent spots for corridors        -RAK-     */
  359. /*
  360.  * note that y, x is always in_bounds(), hence no need to check that j, k are
  361.  * in_bounds(), even if they are 0 or cur_x-1 is still works 
  362.  */
  363. int 
  364. next_to_corr(y, x)
  365. register int y, x;
  366. {
  367.     register int        k, j, i;
  368.     register cave_type *c_ptr;
  369.  
  370.     i = 0;
  371.     for (j = y - 1; j <= (y + 1); j++)
  372.     for (k = x - 1; k <= (x + 1); k++) {
  373.         c_ptr = &cave[j][k];
  374.     /* should fail if there is already a door present */
  375.         if (c_ptr->fval == CORR_FLOOR
  376.         && (c_ptr->tptr == 0 || t_list[c_ptr->tptr].tval < TV_MIN_DOORS))
  377.         i++;
  378.     }
  379.     return (i);
  380. }
  381.  
  382.  
  383. /* generates damage for 2d6 style dice rolls */
  384. int 
  385. damroll(num, sides)
  386. int num, sides;
  387. {
  388.     register int i, sum = 0;
  389.  
  390.     for (i = 0; i < num; i++)
  391.     sum += randint(sides);
  392.     return (sum);
  393. }
  394.  
  395. int 
  396. pdamroll(array)
  397. int8u *array;
  398. {
  399.     return damroll((int)array[0], (int)array[1]);
  400. }
  401.  
  402.  
  403. /*
  404.  * A simple, fast, integer-based line-of-sight algorithm.  By Joseph Hall,
  405.  * 4116 Brewster Drive, Raleigh NC 27606.  Email to jnh@ecemwl.ncsu.edu. 
  406.  *
  407.  * Returns TRUE if a line of sight can be traced from x0, y0 to x1, y1. 
  408.  *
  409.  * The LOS begins at the center of the tile [x0, y0] and ends at the center of
  410.  * the tile [x1, y1].  If los() is to return TRUE, all of the tiles this line
  411.  * passes through must be transparent, WITH THE EXCEPTIONS of the starting
  412.  * and ending tiles. 
  413.  *
  414.  * We don't consider the line to be "passing through" a tile if it only passes
  415.  * across one corner of that tile. 
  416.  */
  417.  
  418. /*
  419.  * Because this function uses (short) ints for all calculations, overflow may
  420.  * occur if deltaX and deltaY exceed 90. 
  421.  */
  422.  
  423. int 
  424. los(fromY, fromX, toY, toX)
  425. int fromY, fromX, toY, toX;
  426. {
  427.     register int tmp, deltaX, deltaY;
  428.  
  429.     deltaX = toX - fromX;
  430.     deltaY = toY - fromY;
  431.  
  432. /* Adjacent? */
  433.     if ((deltaX < 2) && (deltaX > -2) && (deltaY < 2) && (deltaY > -2))
  434.     return TRUE;
  435.  
  436. /* Handle the cases where deltaX or deltaY == 0. */
  437.     if (deltaX == 0) {
  438.     register int        p_y;   /* y position -- loop variable     */
  439.  
  440.     if (deltaY < 0) {
  441.         tmp = fromY;
  442.         fromY = toY;
  443.         toY = tmp;
  444.     }
  445.     for (p_y = fromY + 1; p_y < toY; p_y++)
  446.         if (cave[p_y][fromX].fval >= MIN_CLOSED_SPACE)
  447.         return FALSE;
  448.     return TRUE;
  449.     } else if (deltaY == 0) {
  450.     register int        px;       /* x position -- loop variable     */
  451.  
  452.     if (deltaX < 0) {
  453.         tmp = fromX;
  454.         fromX = toX;
  455.         toX = tmp;
  456.     }
  457.     for (px = fromX + 1; px < toX; px++)
  458.         if (cave[fromY][px].fval >= MIN_CLOSED_SPACE)
  459.         return FALSE;
  460.     return TRUE;
  461.     }
  462.  
  463. /* handle Knightlike shapes -CWS */
  464.  
  465.     if (MY_ABS(deltaX) == 1) {
  466.     if (deltaY == 2) {
  467.         if (cave[fromY + 1][fromX].fval <= MAX_OPEN_SPACE)
  468.         return TRUE;
  469.     } else if (deltaY == (-2)) {
  470.         if (cave[fromY - 1][fromX].fval <= MAX_OPEN_SPACE)
  471.         return TRUE;
  472.     }
  473.     } else if (MY_ABS(deltaY) == 1) {
  474.     if (deltaX == 2) {
  475.         if (cave[fromY][fromX + 1].fval <= MAX_OPEN_SPACE)
  476.         return TRUE;
  477.     } else if (deltaX == (-2)) {
  478.         if (cave[fromY][fromX - 1].fval <= MAX_OPEN_SPACE)
  479.         return TRUE;
  480.     }
  481.     }
  482.  
  483. /*
  484.  * Now, we've eliminated all the degenerate cases. In the computations below,
  485.  * dy (or dx) and m are multiplied by a scale factor, scale = abs(deltaX *
  486.  * deltaY * 2), so that we can use integer arithmetic. 
  487.  */
  488.  
  489.     {
  490.     register int        px,       /* x position             */
  491.                         p_y,   /* y position             */
  492.                         scale2;/* above scale factor / 2         */
  493.     int                 scale, /* above scale factor         */
  494.                         xSign, /* sign of deltaX             */
  495.                         ySign, /* sign of deltaY             */
  496.                         m;       /* slope or 1/slope of LOS         */
  497.  
  498.     scale2 = MY_ABS(deltaX * deltaY);
  499.     scale = scale2 << 1;
  500.     xSign = (deltaX < 0) ? -1 : 1;
  501.     ySign = (deltaY < 0) ? -1 : 1;
  502.  
  503.     /*
  504.      * Travel from one end of the line to the other, oriented along the
  505.      * longer axis. 
  506.      */
  507.  
  508.     if (MY_ABS(deltaX) >= MY_ABS(deltaY)) {
  509.         register int        dy;/* "fractional" y position     */
  510.  
  511.     /*
  512.      * We start at the border between the first and second tiles, where
  513.      * the y offset = .5 * slope.  Remember the scale factor.  We have: 
  514.      *
  515.      * m = deltaY / deltaX * 2 * (deltaY * deltaX) = 2 * deltaY * deltaY. 
  516.      */
  517.  
  518.         dy = deltaY * deltaY;
  519.         m = dy << 1;
  520.         px = fromX + xSign;
  521.  
  522.     /* Consider the special case where slope == 1. */
  523.         if (dy == scale2) {
  524.         p_y = fromY + ySign;
  525.         dy -= scale;
  526.         } else
  527.         p_y = fromY;
  528.  
  529.         while (toX - px) {
  530.         if (cave[p_y][px].fval >= MIN_CLOSED_SPACE)
  531.             return FALSE;
  532.  
  533.         dy += m;
  534.         if (dy < scale2)
  535.             px += xSign;
  536.         else if (dy > scale2) {
  537.             p_y += ySign;
  538.             if (cave[p_y][px].fval >= MIN_CLOSED_SPACE)
  539.             return FALSE;
  540.             px += xSign;
  541.             dy -= scale;
  542.         } else {
  543.         /*
  544.          * This is the case, dy == scale2, where the LOS exactly
  545.          * meets the corner of a tile. 
  546.          */
  547.             px += xSign;
  548.             p_y += ySign;
  549.             dy -= scale;
  550.         }
  551.         }
  552.         return TRUE;
  553.     } else {
  554.         register int        dx;/* "fractional" x position     */
  555.  
  556.         dx = deltaX * deltaX;
  557.         m = dx << 1;
  558.  
  559.         p_y = fromY + ySign;
  560.         if (dx == scale2) {
  561.         px = fromX + xSign;
  562.         dx -= scale;
  563.         } else
  564.         px = fromX;
  565.  
  566.         while (toY - p_y) {
  567.         if (cave[p_y][px].fval >= MIN_CLOSED_SPACE)
  568.             return FALSE;
  569.         dx += m;
  570.         if (dx < scale2)
  571.             p_y += ySign;
  572.         else if (dx > scale2) {
  573.             px += xSign;
  574.             if (cave[p_y][px].fval >= MIN_CLOSED_SPACE)
  575.             return FALSE;
  576.             p_y += ySign;
  577.             dx -= scale;
  578.         } else {
  579.             px += xSign;
  580.             p_y += ySign;
  581.             dx -= scale;
  582.         }
  583.         }
  584.         return TRUE;
  585.     }
  586.     }
  587. }
  588.  
  589.  
  590. /* Returns symbol for given row, column            -RAK-     */
  591. unsigned char 
  592. loc_symbol(y, x)
  593. int y, x;
  594. {
  595.     register cave_type    *cave_ptr;
  596.     register struct flags *f_ptr;
  597.  
  598.     cave_ptr = &cave[y][x];
  599.     f_ptr = &py.flags;
  600.  
  601.     if ((cave_ptr->cptr == 1) && (!find_flag || find_prself))
  602.     return '@';
  603.     if (f_ptr->status & PY_BLIND)
  604.     return ' ';
  605.     if ((f_ptr->image > 0) && (randint(12) == 1))
  606.     return randint(95) + 31;
  607.     if ((cave_ptr->cptr > 1) && (m_list[cave_ptr->cptr].ml))
  608.     return c_list[m_list[cave_ptr->cptr].mptr].cchar;
  609.     if (!cave_ptr->pl && !cave_ptr->tl && !cave_ptr->fm)
  610.     return ' ';
  611.     if ((cave_ptr->tptr != 0)
  612.     && (t_list[cave_ptr->tptr].tval != TV_INVIS_TRAP))
  613.     return t_list[cave_ptr->tptr].tchar;
  614.     if (cave_ptr->fval <= MAX_CAVE_FLOOR)
  615.     return '.';
  616.     if (cave_ptr->fval == GRANITE_WALL || cave_ptr->fval == BOUNDARY_WALL
  617.     || highlight_seams == FALSE) {
  618. #ifdef MSDOS
  619.     return wallsym;
  620. #else
  621. #ifndef ATARIST_MWC
  622.     return '#';
  623. #else
  624.     return (unsigned char)240;
  625. #endif
  626. #endif
  627.     } else   /* Originally set highlight bit, but that is not portable,
  628.           * now use the percent sign instead. */
  629.     return '%';
  630. }
  631.  
  632.  
  633. /* Tests a spot for light or field mark status        -RAK-     */
  634. int 
  635. test_light(y, x)
  636. int y, x;
  637. {
  638.     register cave_type *cave_ptr;
  639.  
  640.     cave_ptr = &cave[y][x];
  641.     if (cave_ptr->pl || cave_ptr->tl || cave_ptr->fm)
  642.     return (TRUE);
  643.     else
  644.     return (FALSE);
  645. }
  646.  
  647.  
  648. /* Prints the map of the dungeon            -RAK-     */
  649. void 
  650. prt_map()
  651. {
  652.     register int           i, j, k;
  653.     register unsigned char tmp_char;
  654.  
  655.     k = 0;
  656.     for (i = panel_row_min; i <= panel_row_max; i++) {    /* Top to bottom */
  657.     k++;
  658.     erase_line(k, 13);
  659.  
  660.     for (j = panel_col_min; j <= panel_col_max; j++) {    /* Left to right */
  661.         tmp_char = loc_symbol(i, j);
  662.         if (tmp_char != ' ')
  663.         print(tmp_char, i, j);
  664.     }
  665.     }
  666. }
  667.  
  668.  
  669. /* Compact monsters                    -RAK-     */
  670. /*
  671.  * Return TRUE if any monsters were deleted, FALSE if could not delete any
  672.  * monsters. 
  673.  */
  674. int 
  675. compact_monsters()
  676. {
  677.     register int           i;
  678.     int                    cur_dis, delete_any;
  679.     register monster_type *mon_ptr;
  680.  
  681.     msg_print("Compacting monsters...");
  682.  
  683.     cur_dis = 66;
  684.     delete_any = FALSE;
  685.     do {
  686.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  687.         mon_ptr = &m_list[i];
  688.         if ((cur_dis < mon_ptr->cdis) && (randint(3) == 1)) {
  689.         /* Don't compact Melkor! */
  690.         if (c_list[mon_ptr->mptr].cmove & CM_WIN)
  691.         /* do nothing */
  692.             ;
  693.  
  694.         /* in case this is called from within creatures(), this is a
  695.          * horrible hack, the m_list/creatures() code needs to be
  696.          * rewritten 
  697.          */
  698.         else if (hack_monptr < i) {
  699.             delete_monster(i);
  700.             delete_any = TRUE;
  701.         } else
  702.  
  703.         /* fix1_delete_monster() does not decrement mfptr, so don't
  704.          * set delete_any if this was called 
  705.          */
  706.             fix1_delete_monster(i);
  707.         }
  708.     }
  709.     if (!delete_any) {
  710.         cur_dis -= 6;
  711.     /* can't do anything else but abort, if can't delete any monsters */
  712.         if (cur_dis < 0)
  713.         return FALSE;
  714.     }
  715.     }
  716.     while (!delete_any);
  717.     return TRUE;
  718. }
  719.  
  720.  
  721. /* Add to the players food time                -RAK-     */
  722. void 
  723. add_food(num)
  724. int num;
  725. {
  726.     register struct flags *p_ptr;
  727.     register int           extra, penalty;
  728.  
  729.     p_ptr = &py.flags;
  730.     if (p_ptr->food < 0)
  731.     p_ptr->food = 0;
  732.     p_ptr->food += num;
  733.     if (num > 0 && p_ptr->food <= 0)
  734.     p_ptr->food = 32000;       /* overflow check */
  735.     if (p_ptr->food > PLAYER_FOOD_MAX) {
  736.     msg_print("You are bloated from overeating. ");
  737.  
  738.     /* Calculate how much of num is responsible for the bloating. Give the
  739.      * player food credit for 1/50, and slow him for that many turns also.  
  740.      */
  741.     extra = p_ptr->food - PLAYER_FOOD_MAX;
  742.     if (extra > num)
  743.         extra = num;
  744.     penalty = extra / 50;
  745.  
  746.     p_ptr->slow += penalty;
  747.     if (extra == num)
  748.         p_ptr->food = p_ptr->food - num + penalty;
  749.     else
  750.         p_ptr->food = PLAYER_FOOD_MAX + penalty;
  751.     } else if (p_ptr->food > PLAYER_FOOD_FULL)
  752.     msg_print("You are full. ");
  753. }
  754.  
  755.  
  756. /* Returns a pointer to next free space            -RAK-     */
  757. int 
  758. popm()
  759. {
  760.     if (mfptr == MAX_MALLOC)
  761.     if (!compact_monsters())
  762.         return (-1);
  763.     return (mfptr++);
  764. }
  765.  
  766.  
  767. /* Gives Max hit points                    -RAK-     */
  768. int 
  769. max_hp(array)
  770. int8u *array;
  771. {
  772.     return ((int)(array[0]) * (int)(array[1]));
  773. }
  774.  
  775.  
  776. /* Places a monster at given location            -RAK-     */
  777. int 
  778. place_monster(y, x, z, slp)
  779. register int y, x, z;
  780. int          slp;
  781. {
  782.     register int           cur_pos, j, ny,nx,count;
  783.     register monster_type *mon_ptr;
  784.     char                   buf[100];
  785.  
  786.     if ((z < 0) || (z >= MAX_CREATURES))
  787.     return FALSE;        /* another paranoia check -CFT */
  788.  
  789.     if (!test_place(y, x))
  790.     return FALSE;        /* YA paranoia check -CFT */
  791.  
  792.     if (c_list[z].cdefense & UNIQUE) {
  793.     if (u_list[z].exist) {
  794.         if (wizard) {
  795.         (void)sprintf(buf, "Tried to create %s but exists.", c_list[z].name);
  796.         msg_print(buf);
  797.         }
  798.         return FALSE;
  799.     }
  800.     if (u_list[z].dead) {
  801.         if (wizard) {
  802.         (void)sprintf(buf, "Tried to create %s but dead.", c_list[z].name);
  803.         msg_print(buf);
  804.         }
  805.         return FALSE;
  806.     }
  807.     u_list[z].exist = 1;
  808.     }
  809.     cur_pos = popm();           /* from um55, paranoia error check... */
  810.     if (cur_pos == -1)
  811.     return FALSE;
  812.  
  813.     if ((wizard || peek) && (c_list[z].cdefense & UNIQUE))
  814.     msg_print(c_list[z].name);
  815.     if (c_list[z].level > (unsigned)dun_level) {
  816.     int                 c;
  817.  
  818.     rating += ((c = c_list[z].level - dun_level) > 30) ? 15 : c / 2;
  819.     if (c_list[z].cdefense & UNIQUE)
  820.         rating += (c_list[z].level - dun_level) / 2;
  821.     }
  822.     mon_ptr = &m_list[cur_pos];
  823.     mon_ptr->fy = y;
  824.     mon_ptr->fx = x;
  825.     mon_ptr->mptr = z;
  826.     if ((c_list[z].cdefense & MAX_HP) || be_nasty)
  827.     mon_ptr->hp = max_hp(c_list[z].hd);
  828.     else
  829.     mon_ptr->hp = pdamroll(c_list[z].hd);
  830.     mon_ptr->maxhp = mon_ptr->hp;
  831.     mon_ptr->cspeed = c_list[z].speed - 10;
  832.     mon_ptr->stunned = 0;
  833.     mon_ptr->confused = 0;
  834.     mon_ptr->monfear = 0;
  835.     mon_ptr->cdis = distance(char_row, char_col, y, x);
  836.     mon_ptr->ml = FALSE;
  837.     cave[y][x].cptr = cur_pos;
  838.  
  839.     if (slp) {
  840.     if (c_list[z].sleep == 0)
  841.         mon_ptr->csleep = 0;
  842.     else
  843.         mon_ptr->csleep = ((int)c_list[z].sleep * 2) +
  844.         randint((int)c_list[z].sleep * 10);
  845.     } else
  846.   /* to give the player a sporting chance, any monster that appears in
  847.          line-of-sight and can cast spells or breathe, should be asleep.
  848.           This is an extension of Um55's sleeping dragon code... */
  849.     if (((c_list[z].spells & (CAUSE_LIGHT|CAUSE_SERIOUS|HOLD_PERSON|
  850.                                   BLINDNESS|CONFUSION|FEAR|SLOW|BREATH_L|
  851.                                   BREATH_G|BREATH_A|BREATH_FR|BREATH_FI|
  852.                                   FIRE_BOLT|FROST_BOLT|ACID_BOLT|MAG_MISS|
  853.                                   CAUSE_CRIT|FIRE_BALL|FROST_BALL|MANA_BOLT))
  854.           || (c_list[z].spells2 & (BREATH_CH|BREATH_SH|BREATH_SD|BREATH_CO|
  855.                                   BREATH_DI|BREATH_LD|LIGHT_BOLT|LIGHT_BALL|
  856.                                   ACID_BALL|TRAP_CREATE|RAZOR|MIND_BLAST|
  857.                                   MISSILE|PLASMA_BOLT|NETHER_BOLT|ICE_BOLT|
  858.                                   FORGET|BRAIN_SMASH|ST_CLOUD|TELE_LEV|
  859.                                   WATER_BOLT|WATER_BALL|NETHER_BALL|BREATH_NE))
  860.           || (c_list[z].spells3 & (BREATH_WA|BREATH_SL|BREATH_LT|BREATH_TI|
  861.                                   BREATH_GR|BREATH_DA|BREATH_PL|ARROW|
  862.                                   DARK_STORM|MANA_STORM)))
  863.        && (los(y,x, char_row, char_col)))
  864.       mon_ptr->csleep = randint(4);   /* if asleep only to prevent
  865.                                        * summon-breathe-breathe-breathe-die,
  866.                                        * then don't sleep long -CFT */
  867.     else mon_ptr->csleep = 0;
  868.     update_mon(cur_pos);       /* light up the monster if we can see it... -CFT */
  869.  
  870. /* Unique kobolds, Liches, orcs, Ogres, Trolls, yeeks, and & demons -DGK
  871.  * But not skeletons, because that would include druj, making Cantoras
  872.  * amazingly tough -CFT
  873.  */
  874.     if (c_list[z].cdefense & UNIQUE) {
  875.     j = c_list[z].cchar;
  876.     if ((j=='k')||(j=='L')||(j=='o')||(j=='O')||(j=='T')||(j=='y')||
  877.         (j=='I')||(j=='&')) {
  878.         for (cur_pos=MAX_CREATURES-1;cur_pos>=0;cur_pos--)
  879.         if ((c_list[cur_pos].cchar==j) &&
  880.             (c_list[cur_pos].level<=c_list[z].level) &&
  881.             !(c_list[cur_pos].cdefense & UNIQUE)) {
  882.             count = 0;
  883.             do {
  884.             ny=y+randint(7)-4;
  885.             nx=x+randint(7)-4;
  886.             count++;
  887.             } while (!test_place(ny,nx) && (count<51));
  888.             if ((j=='k')||(j=='y')||(j=='&')||(c_list[cur_pos].cdefense&GROUP))
  889.             place_group(ny,nx,cur_pos,slp);
  890.             else
  891.             place_monster(ny,nx,cur_pos,slp);
  892.         }
  893.     }
  894.     }
  895.     return TRUE;
  896. }
  897.  
  898. /* Places a monster at given location            -RAK-     */
  899. int 
  900. place_win_monster()
  901. {
  902.     register int           y, x, cur_pos;
  903.     register monster_type *mon_ptr;
  904.  
  905.     if (!total_winner) {
  906.     cur_pos = popm();
  907.     /* paranoia error check, from um55 -CFT */
  908.     if (cur_pos == -1)
  909.         return FALSE;
  910.  
  911.     if (wizard || peek)
  912.         msg_print("Placing win monster");
  913.  
  914.     mon_ptr = &m_list[cur_pos];
  915.     do {
  916.         y = randint(cur_height - 2);
  917.         x = randint(cur_width - 2);
  918.     }
  919.     while ((cave[y][x].fval >= MIN_CLOSED_SPACE) || (cave[y][x].cptr != 0)
  920.            || (cave[y][x].tptr != 0) ||
  921.            (distance(y, x, char_row, char_col) <= MAX_SIGHT));
  922.     mon_ptr->fy = y;
  923.     mon_ptr->fx = x;
  924.     mon_ptr->mptr = MAX_CREATURES - 2;
  925.     if (c_list[mon_ptr->mptr].cdefense & MAX_HP)
  926.         mon_ptr->hp = max_hp(c_list[mon_ptr->mptr].hd);
  927.     else
  928.         mon_ptr->hp = pdamroll(c_list[mon_ptr->mptr].hd);
  929.     mon_ptr->cspeed = c_list[mon_ptr->mptr].speed - 10;
  930.     mon_ptr->stunned = 0;
  931.     mon_ptr->cdis = distance(char_row, char_col, y, x);
  932.     cave[y][x].cptr = cur_pos;
  933.     mon_ptr->csleep = 0;
  934.     }
  935.     return TRUE;
  936. }
  937.  
  938.  
  939. static char *
  940. cap(str)
  941. char *str;
  942. {
  943.     if ((*str >= 'a') && (*str <= 'z'))
  944.     *str = *str - 'a' + 'A';
  945.     return str;
  946. }
  947.  
  948.  
  949. void 
  950. set_ghost(g, name, r, c, l)
  951. creature_type      *g;
  952. char               *name;
  953. int                 r, c, l;
  954. {
  955.     char ghost_race[20];
  956.     char ghost_class[20];
  957.     int  i;
  958.  
  959.     /* Allocate storage for name -TL -- braindamaged ghost name spoo -CWS */
  960.     if (c_list[MAX_CREATURES - 1].name == NULL) {
  961.     c_list[MAX_CREATURES - 1].name = (char*)malloc(101);
  962.     bzero((char *) c_list[MAX_CREATURES - 1].name, 101);
  963.     *((char *) c_list[MAX_CREATURES - 1].name) = 'A';
  964.     }
  965.  
  966.     switch (r) {
  967.       case 0:
  968.       case 8:
  969.     strcpy(ghost_race, "human");
  970.     break;
  971.       case 1:
  972.       case 2:
  973.       case 9:
  974.     strcpy(ghost_race, "elf");
  975.     break;
  976.       case 3:
  977.     strcpy(ghost_race, "hobbit");
  978.     break;
  979.       case 4:
  980.     strcpy(ghost_race, "gnome");
  981.     break;
  982.       case 5:
  983.     strcpy(ghost_race, "dwarf");
  984.     break;
  985.       case 6:
  986.     strcpy(ghost_race, "orc");
  987.     break;
  988.       case 7:
  989.     strcpy(ghost_race, "troll");
  990.     break;
  991.     }
  992.     switch (c) {
  993.       case 0:
  994.     strcpy(ghost_class, "warrior");
  995.     break;
  996.       case 1:
  997.     strcpy(ghost_class, "mage");
  998.     break;
  999.       case 2:
  1000.     strcpy(ghost_class, "priest");
  1001.     break;
  1002.       case 3:
  1003.     strcpy(ghost_class, "rogue");
  1004.     break;
  1005.       case 4:
  1006.     strcpy(ghost_class, "ranger");
  1007.     break;
  1008.       case 5:
  1009.     strcpy(ghost_class, "paladin");
  1010.     break;
  1011.     }
  1012.     g->level = l;
  1013.     g->sleep = 0;
  1014.     g->aaf = 100;
  1015.     g->mexp = l * 5 + 5;
  1016.     g->spells2 = NONE8;
  1017.     if (!dun_level) {
  1018.     sprintf((char *)g->name, "%s, the %s %s", cap(name),
  1019.         cap(ghost_race), cap(ghost_class));
  1020.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_90 | HAS_60 | GOOD);
  1021.     if (l > 10)
  1022.         g->cmove |= (HAS_1D2);
  1023.     if (l > 18)
  1024.         g->cmove |= (HAS_2D2);
  1025.     if (l > 23)
  1026.         g->cmove |= (HAS_4D2);
  1027.     if (l > 40) {
  1028.         g->cmove |= (SPECIAL);
  1029.         g->cmove &= (~HAS_4D2);
  1030.     }
  1031.     for (i = 0; i <= (l / 5); i++)    /* Add some random resists -DGK */
  1032.         switch ((int) randint(13)) {
  1033.           case 1:
  1034.           case 2:
  1035.           case 3:
  1036.         g->cdefense |= (IM_FIRE);
  1037.           case 4:
  1038.           case 5:
  1039.           case 6:
  1040.         g->cdefense |= (IM_ACID);
  1041.           case 7:
  1042.           case 8:
  1043.           case 9:
  1044.         g->cdefense |= (IM_FROST);
  1045.           case 10:
  1046.           case 11:
  1047.           case 12:
  1048.         g->cdefense |= (IM_LIGHTNING);
  1049.           case 13:
  1050.         g->cdefense |= (IM_POISON);
  1051.         }
  1052.     switch (c) {
  1053.       case 0:           /* Warrior */
  1054.         g->spells = NONE8;
  1055.         break;
  1056.       case 1:           /* Mage */
  1057.         g->spells |= (0x3L | BLINK | MAG_MISS | SLOW | CONFUSION);
  1058.         if (l > 5)
  1059.         g->spells2 |= ST_CLOUD;
  1060.         if (l > 7)
  1061.         g->spells2 |= LIGHT_BOLT;
  1062.         if (l > 10)
  1063.         g->spells |= FROST_BOLT;
  1064.         if (l > 12)
  1065.         g->spells |= TELE;
  1066.         if (l > 15)
  1067.         g->spells |= ACID_BOLT;
  1068.         if (l > 20)
  1069.         g->spells |= FIRE_BOLT;
  1070.         if (l > 25)
  1071.         g->spells |= FROST_BALL;
  1072.         if (l > 25)
  1073.         g->spells2 |= HASTE;
  1074.         if (l > 30)
  1075.         g->spells |= FIRE_BALL;
  1076.         if (l > 40)
  1077.         g->spells |= MANA_BOLT;
  1078.         break;
  1079.       case 3:           /* Rogue */
  1080.         g->spells |= (0x5L | BLINK);
  1081.         if (l > 10)
  1082.         g->spells |= CONFUSION;
  1083.         if (l > 18)
  1084.         g->spells |= SLOW;
  1085.         if (l > 25)
  1086.         g->spells |= TELE;
  1087.         if (l > 30)
  1088.         g->spells |= HOLD_PERSON;
  1089.         if (l > 35)
  1090.         g->spells |= TELE_TO;
  1091.         break;
  1092.       case 4:           /* Ranger */
  1093.         g->spells |= (0x8L | MAG_MISS);
  1094.         if (l > 5)
  1095.         g->spells2 |= ST_CLOUD;
  1096.         if (l > 7)
  1097.         g->spells2 |= LIGHT_BOLT;
  1098.         if (l > 10)
  1099.         g->spells |= FROST_BOLT;
  1100.         if (l > 18)
  1101.         g->spells |= ACID_BOLT;
  1102.         if (l > 25)
  1103.         g->spells |= FIRE_BOLT;
  1104.         if (l > 30)
  1105.         g->spells |= FROST_BALL;
  1106.         if (l > 35)
  1107.         g->spells |= FIRE_BALL;
  1108.         break;
  1109.       case 2:           /* Priest */
  1110.       case 5:           /* Paladin */
  1111.         g->spells |= (0x4L | CAUSE_LIGHT | FEAR);
  1112.         if (l > 5)
  1113.         g->spells2 |= HEAL;
  1114.         if (l > 10)
  1115.         g->spells |= (CAUSE_SERIOUS | BLINDNESS);
  1116.         if (l > 18)
  1117.         g->spells |= HOLD_PERSON;
  1118.         if (l > 25)
  1119.         g->spells |= CONFUSION;
  1120.         if (l > 30)
  1121.         g->spells |= CAUSE_CRIT;
  1122.         if (l > 35)
  1123.         g->spells |= MANA_DRAIN;
  1124.         break;
  1125.     }
  1126.  
  1127.     g->cdefense |= (CHARM_SLEEP | EVIL);
  1128.     if (r == 6)
  1129.         g->cdefense |= ORC;
  1130.     else if (r == 7)
  1131.         g->cdefense |= TROLL;
  1132.     g->ac = 15 + randint(15);
  1133.     if (c == 0 || c >= 3)
  1134.         g->ac += randint(60);
  1135.     if ((c == 1 || c == 3) && l > 25)    /* High level mages and
  1136.                          * rogues are fast... */
  1137.         g->speed = 12;
  1138.     else
  1139.         g->speed = 11;
  1140.     g->cchar = 'p';
  1141.     g->hd[1] = 1;
  1142.     g->damage[0] = 5 + ((l > 18) ? 18 : l);
  1143.     g->damage[1] = g->damage[0];
  1144.     switch (c) {
  1145.       case 0:
  1146.         g->damage[2] = ((l < 30) ? (5 + ((l > 18) ? 18 : l)) : 235);
  1147.         g->damage[3] = g->damage[2];
  1148.         break;
  1149.       case 1:
  1150.       case 2:
  1151.         g->damage[2] = 0;
  1152.         g->damage[3] = 0;
  1153.         break;
  1154.       case 3:
  1155.         g->damage[2] = g->damage[3] = ((l < 30) ? 149 : 232);
  1156.         break;
  1157.       case 5:
  1158.       case 4:
  1159.         g->damage[2] = g->damage[3] = g->damage[1];
  1160.         break;
  1161.     }
  1162.     return;
  1163.     }
  1164.     switch ((int) (g->level / 4) + randint(3)) {
  1165.       case 1:
  1166.       case 2:
  1167.       case 3:
  1168.     sprintf((char *)g->name, "%s, the Skeleton %s", name, ghost_race);
  1169.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_90 | GOOD);
  1170.     g->spells |= (NONE8);
  1171.     g->cdefense |= (IM_POISON | CHARM_SLEEP | UNDEAD | EVIL | IM_FROST | NO_INFRA);
  1172.     if (r == 6)
  1173.         g->cdefense |= ORC;
  1174.     else if (r == 7)
  1175.         g->cdefense |= TROLL;
  1176.     g->ac = 26;
  1177.     g->speed = 11;
  1178.     g->cchar = 's';
  1179.     g->hd[1] = 1;
  1180.     g->damage[0] = 5;
  1181.     g->damage[1] = 5;
  1182.     g->damage[2] = 0;
  1183.     g->damage[3] = 0;
  1184.     break;
  1185.       case 4:
  1186.       case 5:
  1187.     sprintf((char *)g->name, "%s, the %s zombie", name, cap(ghost_race));
  1188.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_60 | HAS_90 | GOOD);
  1189.     g->spells |= (NONE8);
  1190.     g->cdefense |= (IM_POISON | CHARM_SLEEP | UNDEAD | EVIL | NO_INFRA);
  1191.  
  1192.     if (r == 6)
  1193.         g->cdefense |= ORC;
  1194.     else if (r == 7)
  1195.         g->cdefense |= TROLL;
  1196.     g->ac = 30;
  1197.     g->speed = 11;
  1198.     g->cchar = 'z';
  1199.     g->hd[1] *= 2;
  1200.     g->damage[0] = 8;
  1201.     g->damage[1] = 0;
  1202.     g->damage[2] = 0;
  1203.     g->damage[3] = 0;
  1204.     break;
  1205.       case 6:
  1206.     sprintf((char *) g->name, "%s, the Poltergeist", name);
  1207.     g->cmove |= (MV_INVIS | MV_ATT_NORM | CARRY_OBJ |
  1208.              GOOD | HAS_1D2 | MV_75 | THRO_WALL);
  1209.     g->spells |= (NONE8);
  1210.     g->cdefense |= (IM_POISON | CHARM_SLEEP | UNDEAD | EVIL | IM_FROST | NO_INFRA);
  1211.     g->ac = 20;
  1212.     g->speed = 13;
  1213.     g->cchar = 'G';
  1214.     g->damage[0] = 5;
  1215.     g->damage[1] = 5;
  1216.     g->damage[2] = 93;
  1217.     g->damage[3] = 93;
  1218.     g->mexp = (g->mexp * 3) / 2;
  1219.     break;
  1220.       case 7:
  1221.       case 8:
  1222.     sprintf((char *)g->name, "%s, the Mummified %s", name, cap(ghost_race));
  1223.     g->cmove |= (MV_ATT_NORM | CARRY_OBJ | HAS_1D2 | GOOD);
  1224.     g->spells |= (NONE8);
  1225.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | NO_INFRA);
  1226.     if (r == 6)
  1227.         g->cdefense |= ORC;
  1228.     else if (r == 7)
  1229.         g->cdefense |= TROLL;
  1230.     g->ac = 35;
  1231.     g->speed = 11;
  1232.     g->cchar = 'M';
  1233.     g->hd[1] *= 2;
  1234.     g->damage[0] = 16;
  1235.     g->damage[1] = 16;
  1236.     g->damage[2] = 16;
  1237.     g->damage[3] = 0;
  1238.     g->mexp = (g->mexp * 3) / 2;
  1239.     break;
  1240.       case 9:
  1241.       case 10:
  1242.     sprintf((char *)g->name, "%s%s spirit", name, (name[strlen(name) - 1] == 's') ?
  1243.         "'" : "'s");
  1244.     g->cmove |= (MV_INVIS | THRO_WALL | MV_ATT_NORM | CARRY_OBJ | HAS_1D2 | GOOD);
  1245.     g->spells |= (NONE8);
  1246.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | IM_FROST | NO_INFRA);
  1247.     g->ac = 20;
  1248.     g->speed = 11;
  1249.     g->cchar = 'G';
  1250.     g->hd[1] *= 2;
  1251.     g->damage[0] = 19;
  1252.     g->damage[1] = 185;
  1253.     g->damage[2] = 99;
  1254.     g->damage[3] = 178;
  1255.     g->mexp = g->mexp * 3;
  1256.     break;
  1257.       case 11:
  1258.     sprintf((char *)g->name, "%s%s ghost", name, (name[strlen(name) - 1] == 's') ?
  1259.         "'" : "'s");
  1260.     g->cmove |= (MV_INVIS | THRO_WALL | MV_ATT_NORM | CARRY_OBJ | HAS_1D2 | GOOD);
  1261.     g->spells |= (0xFL | HOLD_PERSON | MANA_DRAIN | BLINDNESS);
  1262.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | IM_FROST | NO_INFRA);
  1263.     g->ac = 40;
  1264.     g->speed = 12;
  1265.     g->cchar = 'G';
  1266.     g->hd[1] *= 2;
  1267.     g->damage[0] = 99;
  1268.     g->damage[1] = 99;
  1269.     g->damage[2] = 192;
  1270.     g->damage[3] = 184;
  1271.     g->mexp = (g->mexp * 7) / 2;
  1272.     break;
  1273.       case 12:
  1274.     sprintf((char *) g->name, "%s, the Vampire", name);
  1275.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_2D2 | GOOD);
  1276.     g->spells |= (0x8L | HOLD_PERSON | FEAR | TELE_TO | CAUSE_SERIOUS);
  1277.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | NO_INFRA | HURT_LIGHT);
  1278.     g->ac = 40;
  1279.     g->speed = 11;
  1280.     g->cchar = 'V';
  1281.     g->hd[1] *= 3;
  1282.     g->damage[0] = 20;
  1283.     g->damage[1] = 20;
  1284.     g->damage[2] = 190;
  1285.     g->damage[3] = 0;
  1286.     g->mexp = g->mexp * 3;
  1287.     break;
  1288.       case 13:
  1289.     sprintf((char *)g->name, "%s%s Wraith", name, (name[strlen(name) - 1] == 's') ?
  1290.         "'" : "'s");
  1291.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_4D2 | HAS_2D2 | GOOD);
  1292.     g->spells |= (0x7L | HOLD_PERSON | FEAR | BLINDNESS | CAUSE_CRIT);
  1293.     g->spells2 |= (NETHER_BOLT);
  1294.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | IM_FROST | NO_INFRA |
  1295.             HURT_LIGHT);
  1296.     g->ac = 60;
  1297.     g->speed = 12;
  1298.     g->cchar = 'W';
  1299.     g->hd[1] *= 3;
  1300.     g->damage[0] = 20;
  1301.     g->damage[1] = 20;
  1302.     g->damage[2] = 190;
  1303.     g->damage[3] = 0;
  1304.     g->mexp = g->mexp * 5;
  1305.     break;
  1306.       case 14:
  1307.     sprintf((char *) g->name, "%s, the Vampire Lord", name);
  1308.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_1D2 | SPECIAL);
  1309.     g->spells |= (0x8L | HOLD_PERSON | FEAR | TELE_TO | CAUSE_CRIT);
  1310.     g->spells2 |= (NETHER_BOLT);
  1311.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | NO_INFRA | HURT_LIGHT);
  1312.     g->ac = 80;
  1313.     g->speed = 11;
  1314.     g->cchar = 'V';
  1315.     g->hd[1] *= 2;
  1316.     g->hd[0] = (g->hd[0] * 5) / 2;
  1317.     g->damage[0] = 20;
  1318.     g->damage[1] = 20;
  1319.     g->damage[2] = 20;
  1320.     g->damage[3] = 198;
  1321.     g->mexp = g->mexp * 20;
  1322.     break;
  1323.       case 15:
  1324.     sprintf((char *)g->name, "%s%s ghost", name, (name[strlen(name) - 1] == 's') ?
  1325.         "'" : "'s");
  1326.     g->cmove |= (MV_INVIS | THRO_WALL | MV_ATT_NORM | CARRY_OBJ | HAS_2D2 | SPECIAL);
  1327.     g->spells |= (0x5L | HOLD_PERSON | MANA_DRAIN | BLINDNESS | CONFUSION);
  1328.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_FROST | IM_POISON | NO_INFRA);
  1329.     g->ac = 90;
  1330.     g->speed = 13;
  1331.     g->cchar = 'G';
  1332.     g->hd[1] *= 3;
  1333.     g->damage[0] = 99;
  1334.     g->damage[1] = 99;
  1335.     g->damage[2] = 192;
  1336.     g->damage[3] = 184;
  1337.     g->mexp = g->mexp * 20;
  1338.     break;
  1339.       case 17:
  1340.     sprintf((char *)g->name, "%s, the Lich", name);
  1341.     g->cmove |= (THRO_DR | MV_ATT_NORM | CARRY_OBJ | HAS_2D2 | HAS_1D2 | SPECIAL);
  1342.     g->spells |= (0x3L | FEAR | CAUSE_CRIT | TELE_TO | BLINK | S_UNDEAD | FIRE_BALL |
  1343.               FROST_BALL | HOLD_PERSON | MANA_DRAIN | BLINDNESS | CONFUSION | TELE);
  1344.     g->spells2 |= (BRAIN_SMASH | RAZOR);
  1345.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_FROST | NO_INFRA | IM_POISON
  1346.             | INTELLIGENT);
  1347.     g->ac = 120;
  1348.     g->speed = 12;
  1349.     g->cchar = 'L';
  1350.     g->hd[1] *= 3;
  1351.     g->hd[0] *= 2;
  1352.     g->damage[0] = 181;
  1353.     g->damage[1] = 201;
  1354.     g->damage[2] = 214;
  1355.     g->damage[3] = 181;
  1356.     g->mexp = g->mexp * 50;
  1357.     break;
  1358.       case 18:
  1359.       default:
  1360.     sprintf((char *)g->name, "%s%s ghost", name, (name[strlen(name) - 1] == 's') ?
  1361.         "'" : "'s");
  1362.     g->cmove |= (MV_INVIS | THRO_WALL | MV_ATT_NORM | CARRY_OBJ |
  1363.              HAS_1D2 | HAS_2D2 | SPECIAL);
  1364.     g->spells |= (0x2L | HOLD_PERSON | MANA_DRAIN | BLINDNESS | CONFUSION | TELE_TO);
  1365.     g->spells2 |= (NETHER_BOLT | NETHER_BALL | BRAIN_SMASH | TELE_LEV);
  1366.     g->cdefense |= (CHARM_SLEEP | UNDEAD | EVIL | IM_POISON | IM_FROST | NO_INFRA |
  1367.             INTELLIGENT);
  1368.     g->ac = 130;
  1369.     g->speed = 13;
  1370.     g->cchar = 'G';
  1371.     g->hd[1] *= 2;
  1372.     g->hd[0] = (g->hd[0] * 5) / 2;
  1373.     g->damage[0] = 99;
  1374.     g->damage[1] = 99;
  1375.     g->damage[2] = 192;
  1376.     g->damage[3] = 184;
  1377.     g->mexp = g->mexp * 30;
  1378.     break;
  1379.     }
  1380. }
  1381.  
  1382.  
  1383. /* Places a monster at given location            -RAK-     */
  1384. int 
  1385. place_ghost()
  1386. {
  1387.     register int           y, x, cur_pos;
  1388.     register monster_type *mon_ptr;
  1389.     creature_type         *ghost = &c_list[MAX_CREATURES - 1];
  1390.     char                   tmp[100];
  1391.     char                   name[100];
  1392.     int                    i, j, level;
  1393.     int                    ghost_race;
  1394.     int                    cl;
  1395.  
  1396.     if (!dun_level) {
  1397.     FILE *fp;
  1398.  
  1399.     if (py.misc.lev < 5 || randint(10) > 1)
  1400.         return 0;
  1401.     sprintf(tmp, "%s/%d", ANGBAND_BONES, py.misc.lev);
  1402.     if ((fp = my_tfopen(tmp, "r")) != NULL) {
  1403.         if (fscanf(fp, "%[^\n]\n%d\n%d\n%d", name, &i, &ghost_race, &cl) < 4) {
  1404.         fclose(fp);
  1405.         if (wizard)
  1406.             msg_print("Town:Failed to scan in info properly!");
  1407.         return 0;
  1408.         }
  1409.         fclose(fp);
  1410.         j = 1;
  1411.         if (i > 255) {       /* avoid wrap-around of int8u hitdice, by
  1412.                     * factoring */
  1413.         j = i / 32;
  1414.         i = 32;
  1415.         }
  1416.         ghost->hd[0] = i;       /* set_ghost may adj for race/class/lv */
  1417.         ghost->hd[1] = j;
  1418.         level = py.misc.lev;
  1419.     } else {
  1420.         return 0;
  1421.     }
  1422.     } else {
  1423.     if (14 > randint((dun_level / 2) + 11))
  1424.         return 0;
  1425.     if (randint(3) == 1) {
  1426.         FILE *fp;
  1427.  
  1428.         sprintf(tmp, "%s/%d", ANGBAND_BONES, dun_level);
  1429.         if ((fp = my_tfopen(tmp, "r")) != NULL) {
  1430.         if (fscanf(fp, "%[^\n]\n%d\n%d\n%d", name, &i, &ghost_race, &cl) < 4) {
  1431.             fclose(fp);
  1432.             if (wizard)
  1433.             msg_print("Ghost:Failed to scan in info properly!");
  1434.             return 0;
  1435.         }
  1436.         fclose(fp);
  1437.         j = 1;
  1438.         if (i > 255) {       /* avoid wrap-around of int8u hitdice, by
  1439.                     * factoring */
  1440.             j = i / 32;
  1441.             i = 32;
  1442.         }
  1443.         ghost->hd[0] = i;  /* set_ghost may adj for race/class/lv */
  1444.         ghost->hd[1] = j;
  1445.         level = dun_level;
  1446.         } else {
  1447.         return 0;
  1448.         }
  1449.     } else {
  1450.         return 0;
  1451.     }
  1452.     }
  1453.     set_ghost(ghost, name, ghost_race, cl, level);
  1454.     if (wizard || peek)
  1455.     msg_print(ghost->name);
  1456.     cur_pos = popm();
  1457.     mon_ptr = &m_list[cur_pos];
  1458.     do {
  1459.     y = randint(cur_height - 2);
  1460.     x = randint(cur_width - 2);
  1461.     } while ((cave[y][x].fval >= MIN_CLOSED_SPACE) || (cave[y][x].cptr != 0)
  1462.          || (cave[y][x].tptr != 0) ||
  1463.          (distance(y, x, char_row, char_col) <= MAX_SIGHT));
  1464.     mon_ptr->fy = y;
  1465.     mon_ptr->fx = x;
  1466.     mon_ptr->mptr = (MAX_CREATURES - 1);
  1467.     mon_ptr->hp = (int16) ghost->hd[0] * (int16) ghost->hd[1];
  1468. /* the c_list speed value is 10 greater, so that it can be a int8u */
  1469.     mon_ptr->cspeed = c_list[mon_ptr->mptr].speed - 10;
  1470.     mon_ptr->stunned = 0;
  1471.     mon_ptr->cdis = distance(char_row, char_col, y, x);
  1472.     cave[y][x].cptr = cur_pos;
  1473.     mon_ptr->csleep = 0;
  1474.     return 1;
  1475. }
  1476.  
  1477.  
  1478. /*
  1479.  * Return a monster suitable to be placed at a given level.  This makes high
  1480.  * level monsters (up to the given level) slightly more common than low level
  1481.  * monsters at any given level.   -CJS- 
  1482.  */
  1483. int 
  1484. get_mons_num(level)
  1485. int level;
  1486. {
  1487.     register int i, j, num;
  1488.     int          old = level;
  1489.  
  1490. again:
  1491.     if (level == 0)
  1492.     i = randint(m_level[0]) - 1;
  1493.     else {
  1494.     if (level > MAX_MONS_LEVEL)
  1495.         level = MAX_MONS_LEVEL;
  1496.     if (randint(MON_NASTY) == 1) {
  1497.         i = level / 4 + 1;       /* be a little more civilized about monster depths */
  1498.         if (i > 4)           /* for the first levels -CWS */
  1499.         i = 4;
  1500.         level = level + MY_ABS(i) + 1;
  1501.         if (level > MAX_MONS_LEVEL)
  1502.         level = MAX_MONS_LEVEL;
  1503.     } else {
  1504.  
  1505.     /* This code has been added to make it slightly more likely to get
  1506.      * the higher level monsters. Originally a uniform distribution over
  1507.      * all monsters of level less than or equal to the dungeon level.
  1508.      * This distribution makes a level n monster occur approx 2/n% of the
  1509.      * time on level n, and 1/n*n% are 1st level. 
  1510.      */
  1511.  
  1512.         num = m_level[level] - m_level[0];
  1513.         i = randint(num) - 1;
  1514.         j = randint(num) - 1;
  1515.         if (j > i)
  1516.         i = j;
  1517.         level = c_list[i + m_level[0]].level;
  1518.     }
  1519.     i = m_level[level] - m_level[level - 1];
  1520.     if (i == 0)
  1521.         i++;
  1522.     i = randint(i) - 1 + m_level[level - 1];
  1523.     }
  1524.     if ((c_list[i].level > old) && (c_list[i].cdefense & UNIQUE))
  1525.     goto again;
  1526.     if ((c_list[i].level > (unsigned) dun_level) &&
  1527.     (c_list[i].cdefense & QUESTOR))
  1528.     goto again;
  1529.     return i;
  1530. }
  1531.  
  1532. int 
  1533. get_nmons_num(level)
  1534. int level;
  1535. {
  1536.     register int i, j, num;
  1537.     int          old;
  1538.  
  1539.     old = level;
  1540. again:
  1541.     if (level == 0)
  1542.     i = randint(m_level[0]) - 1;
  1543.     else {
  1544.     if (level > MAX_MONS_LEVEL)
  1545.         level = MAX_MONS_LEVEL;
  1546.     num = m_level[level] - m_level[0];
  1547.     i = randint(num) - 1;
  1548.     i += 15;
  1549.     if (i >= num)
  1550.         i = num - 1;
  1551.     j = randint(num) - 1;
  1552.     if (j > i)
  1553.         i = j;
  1554.     j = randint(num) - 1;
  1555.     if (j > i)
  1556.         i = j;
  1557.     level = c_list[i + m_level[0]].level;
  1558.     i = m_level[level] - m_level[level - 1];
  1559.     if (i == 0)
  1560.         i = 1;
  1561.     i = randint(i) - 1 + m_level[level - 1];
  1562.     }
  1563.     if ((c_list[i].level > old) && (c_list[i].cdefense & UNIQUE))
  1564.     goto again;
  1565.     if (( c_list[i].level > (unsigned) dun_level) &&
  1566.     (c_list[i].cdefense & QUESTOR))
  1567.     goto again;
  1568.     return i;
  1569. }
  1570.  
  1571. /* Ludwig's Brainstorm */
  1572. static int 
  1573. test_place(y, x)
  1574. int y, x;
  1575. {
  1576.     if (!in_bounds(y, x) ||
  1577.     (cave[y][x].fval >= MIN_CLOSED_SPACE) ||
  1578.     (cave[y][x].fval == NULL_WALL) ||
  1579.     (cave[y][x].cptr != 0) ||
  1580.     (y == char_row && x == char_col))
  1581.     return (0);
  1582.     return (1);
  1583. }
  1584.  
  1585. void 
  1586. place_group(y, x, mon, slp)
  1587. int y, x, mon, slp;
  1588. {
  1589. /* prevent level rating from skyrocketing if they are out of depth... */
  1590.     int old = rating;
  1591.     int extra = 0;
  1592.  
  1593.     if (c_list[mon].level > (unsigned) dun_level)
  1594.     extra = (-randint(c_list[mon].level - dun_level));
  1595.                 /* reduce size of group if out-of-depth */
  1596.     else if (c_list[mon].level < (unsigned) dun_level)
  1597. /* if monster is deeper than normal, then travel in bigger packs -CFT */
  1598.     extra = randint(dun_level - c_list[mon].level);
  1599.  
  1600.     if (extra > 12)
  1601.     extra = 12;        /* put an upper bounds on it... -CFT */
  1602.     switch (randint(13) + extra) {
  1603.       case 25:
  1604.     place_monster(y, x - 3, mon, 0);
  1605.       case 24:
  1606.     place_monster(y, x + 3, mon, 0);
  1607.       case 23:
  1608.     place_monster(y - 3, x, mon, 0);
  1609.       case 22:
  1610.     place_monster(y + 3, x, mon, 0);
  1611.       case 21:
  1612.     place_monster(y - 2, x + 1, mon, 0);
  1613.       case 20:
  1614.     place_monster(y + 2, x - 1, mon, 0);
  1615.       case 19:
  1616.     place_monster(y + 2, x + 1, mon, 0);
  1617.       case 18:
  1618.     place_monster(y - 2, x - 1, mon, 0);
  1619.       case 17:
  1620.     place_monster(y + 1, x + 2, mon, 0);
  1621.       case 16:
  1622.     place_monster(y - 1, x - 2, mon, 0);
  1623.       case 15:
  1624.     place_monster(y + 1, x - 2, mon, 0);
  1625.       case 14:
  1626.     place_monster(y - 1, x + 2, mon, 0);
  1627.       case 13:
  1628.     place_monster(y, x - 2, mon, 0);
  1629.       case 12:
  1630.     place_monster(y, x + 2, mon, 0);
  1631.       case 11:
  1632.     place_monster(y + 2, x, mon, 0);
  1633.       case 10:
  1634.     place_monster(y - 2, x, mon, 0);
  1635.       case 9:
  1636.     place_monster(y + 1, x + 1, mon, 0);
  1637.       case 8:
  1638.     place_monster(y + 1, x - 1, mon, 0);
  1639.       case 7:
  1640.     place_monster(y - 1, x - 1, mon, 0);
  1641.       case 6:
  1642.     place_monster(y - 1, x + 1, mon, 0);
  1643.       case 5:
  1644.     place_monster(y, x + 1, mon, 0);
  1645.       case 4:
  1646.     place_monster(y, x - 1, mon, 0);
  1647.       case 3:
  1648.     place_monster(y + 1, x, mon, 0);
  1649.       case 2:
  1650.     place_monster(y - 1, x, mon, 0);
  1651.     rating = old;
  1652.       case 1:
  1653.       default:               /* just in case I screwed up -CFT */
  1654.     place_monster(y, x, mon, 0);
  1655.     }
  1656. }
  1657.  
  1658.  
  1659. /* Allocates a random monster                -RAK-     */
  1660. void 
  1661. alloc_monster(num, dis, slp)
  1662. int num, dis, slp;
  1663. {
  1664.     register int y, x, i;
  1665.     int          mon;
  1666.  
  1667.     for (i = 0; i < num; i++) {
  1668.     do {
  1669.         y = randint(cur_height - 2);
  1670.         x = randint(cur_width - 2);
  1671.     }
  1672.     while (cave[y][x].fval >= MIN_CLOSED_SPACE || (cave[y][x].cptr != 0) ||
  1673.            (distance(y, x, char_row, char_col) <= dis));
  1674.     do {
  1675.         mon = get_mons_num(dun_level);
  1676.     } while (randint(c_list[mon].rarity) > 1);
  1677.  
  1678.     /*
  1679.      * to give the player a sporting chance, any monster that appears in
  1680.      * line-of-sight and can cast spells or breathe, should be asleep. This
  1681.      * is an extension of Um55's sleeping dragon code... 
  1682.      */
  1683.     if (((c_list[mon].spells & (CAUSE_LIGHT | CAUSE_SERIOUS | HOLD_PERSON |
  1684.                 BLINDNESS | CONFUSION | FEAR | SLOW | BREATH_L |
  1685.                    BREATH_G | BREATH_A | BREATH_FR | BREATH_FI |
  1686.                  FIRE_BOLT | FROST_BOLT | ACID_BOLT | MAG_MISS |
  1687.                CAUSE_CRIT | FIRE_BALL | FROST_BALL | MANA_BOLT))
  1688.          || (c_list[mon].spells2 & (BREATH_CH | BREATH_SH | BREATH_SD | BREATH_CO |
  1689.                BREATH_DI | BREATH_LD | LIGHT_BOLT | LIGHT_BALL |
  1690.                   ACID_BALL | TRAP_CREATE | RAZOR | MIND_BLAST |
  1691.                 MISSILE | PLASMA_BOLT | NETHER_BOLT | ICE_BOLT |
  1692.                 FORGET | BRAIN_SMASH | ST_CLOUD | TELE_LEV |
  1693.              WATER_BOLT | WATER_BALL | NETHER_BALL | BREATH_NE))
  1694.          || (c_list[mon].spells3 & (BREATH_WA | BREATH_SL | BREATH_LT | BREATH_TI |
  1695.                  BREATH_GR | BREATH_DA | BREATH_PL | ARROW |
  1696.                     DARK_STORM | MANA_STORM)))
  1697.         && (los(y, x, char_row, char_col)))
  1698.         slp = TRUE;
  1699.  
  1700.     if (!(c_list[mon].cdefense & GROUP))
  1701.         place_monster(y, x, mon, slp);
  1702.     else
  1703.         place_group(y, x, mon, slp);
  1704.     }
  1705. }
  1706.  
  1707.  
  1708. /* Places creature adjacent to given location        -RAK-     */
  1709. int 
  1710. summon_monster(y, x, slp)
  1711. int *y, *x;
  1712. int  slp;
  1713. {
  1714.     register int        i, j, k;
  1715.     int                 l, summon;
  1716.     register cave_type *cave_ptr;
  1717.  
  1718.     i = 0;
  1719.     summon = FALSE;
  1720.     l = get_mons_num(dun_level + MON_SUMMON_ADJ);
  1721.     do {
  1722.     j = *y - 2 + randint(3);
  1723.     k = *x - 2 + randint(3);
  1724.     if (in_bounds(j, k)) {
  1725.         cave_ptr = &cave[j][k];
  1726.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  1727.         if (c_list[l].cdefense & GROUP)
  1728.             place_group(j, k, l, slp);
  1729.         else
  1730.             place_monster(j, k, l, slp);
  1731.         summon = TRUE;
  1732.         i = 9;
  1733.         *y = j;
  1734.         *x = k;
  1735.         }
  1736.     }
  1737.     i++;
  1738.     }
  1739.     while (i <= 9);
  1740.     return (summon);
  1741. }
  1742.  
  1743.  
  1744. /* Places undead adjacent to given location        -RAK-     */
  1745. int 
  1746. summon_undead(y, x)
  1747. int *y, *x;
  1748. {
  1749.     register int        i, j, k;
  1750.     int                 l, m, ctr, summon;
  1751.     register cave_type *cave_ptr;
  1752.  
  1753.     i = 0;
  1754.     summon = FALSE;
  1755.     l = m_level[MAX_MONS_LEVEL];
  1756.     do {
  1757.     m = randint(l) - 1;
  1758.     ctr = 0;
  1759.     do {
  1760.         if ((c_list[m].cdefense & UNDEAD) && !(c_list[m].cdefense & UNIQUE) &&
  1761.         (c_list[m].level < dun_level + 5)) {
  1762.         ctr = 20;
  1763.         l = 0;
  1764.         } else {
  1765.         m++;
  1766.         if (m > l)
  1767.             ctr = 20;
  1768.         else
  1769.             ctr++;
  1770.         }
  1771.     } while (ctr <= 19);
  1772.     } while (l != 0);
  1773.     do {
  1774.     j = *y - 2 + randint(3);
  1775.     k = *x - 2 + randint(3);
  1776.     if (in_bounds(j, k)) {
  1777.         cave_ptr = &cave[j][k];
  1778.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  1779.         place_monster(j, k, m, FALSE);
  1780.         summon = TRUE;
  1781.         i = 9;
  1782.         *y = j;
  1783.         *x = k;
  1784.         }
  1785.     }
  1786.     i++;
  1787.     } while (i <= 9);
  1788.     return (summon);
  1789. }
  1790.  
  1791. /* As for summon undead */
  1792. int 
  1793. summon_demon(lev, y, x)
  1794. int lev;
  1795. int *y, *x;
  1796. {
  1797.     register int        i, j, k;
  1798.     int                 l, m, ctr, summon;
  1799.     register cave_type *cave_ptr;
  1800.  
  1801.     i = 0;
  1802.     summon = FALSE;
  1803.     l = m_level[MAX_MONS_LEVEL];
  1804.     do {
  1805.     m = randint(l) - 1;
  1806.     ctr = 0;
  1807.     do {
  1808.         if (c_list[m].cdefense & DEMON && !(c_list[m].cdefense & UNIQUE) &&
  1809.         (c_list[m].level <= lev)) {
  1810.         ctr = 20;
  1811.         l = 0;
  1812.         } else {
  1813.         m++;
  1814.         if (m > l)
  1815.             ctr = 20;
  1816.         else
  1817.             ctr++;
  1818.         }
  1819.     } while (ctr <= 19);
  1820.     } while (l != 0);
  1821.     do {
  1822.     j = *y - 2 + randint(3);
  1823.     k = *x - 2 + randint(3);
  1824.     if (in_bounds(j, k)) {
  1825.         cave_ptr = &cave[j][k];
  1826.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  1827.         place_monster(j, k, m, FALSE);
  1828.         summon = TRUE;
  1829.         i = 9;
  1830.         *y = j;
  1831.         *x = k;
  1832.         }
  1833.     }
  1834.     i++;
  1835.     } while (i <= 9);
  1836.     return (summon);
  1837. }
  1838.  
  1839. /* As for summon demon:-) ~Ludwig */
  1840. int 
  1841. summon_dragon(y, x)
  1842. int *y, *x;
  1843. {
  1844.     register int        i, j, k;
  1845.     int                 l, m, ctr, summon;
  1846.     register cave_type *cave_ptr;
  1847.  
  1848.     i = 0;
  1849.     summon = FALSE;
  1850.     l = m_level[MAX_MONS_LEVEL];
  1851.     do {
  1852.     m = randint(l) - 1;
  1853.     ctr = 0;
  1854.     do {
  1855.         if (c_list[m].cdefense & DRAGON && !(c_list[m].cdefense & UNIQUE)) {
  1856.         ctr = 20;
  1857.         l = 0;
  1858.         } else {
  1859.         m++;
  1860.         if (m > l)
  1861.             ctr = 20;
  1862.         else
  1863.             ctr++;
  1864.         }
  1865.     }
  1866.     while (ctr <= 19);
  1867.     }
  1868.     while (l != 0);
  1869.     do {
  1870.     j = *y - 2 + randint(3);
  1871.     k = *x - 2 + randint(3);
  1872.     if (in_bounds(j, k)) {
  1873.         cave_ptr = &cave[j][k];
  1874.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  1875.         place_monster(j, k, m, FALSE);
  1876.         summon = TRUE;
  1877.         i = 9;
  1878.         *y = j;
  1879.         *x = k;
  1880.         }
  1881.     }
  1882.     i++;
  1883.     }
  1884.     while (i <= 9);
  1885.     return (summon);
  1886. }
  1887.  
  1888. /* Summon ringwraiths */
  1889. int 
  1890. summon_wraith(y, x)
  1891. int *y, *x;
  1892. {
  1893.     register int        i, j, k;
  1894.     int                 l, m, ctr, summon;
  1895.     register cave_type *cave_ptr;
  1896.  
  1897.     i = 0;
  1898.     summon = FALSE;
  1899.     l = m_level[MAX_MONS_LEVEL];
  1900.     do {
  1901.     m = randint(l) - 1;
  1902.     ctr = 0;
  1903.     do {
  1904.         if (c_list[m].cchar == 'W' && (c_list[m].cdefense & UNIQUE)) {
  1905.         ctr = 20;
  1906.         l = 0;
  1907.         } else {
  1908.         m++;
  1909.         if (m > l)
  1910.             ctr = 20;
  1911.         else
  1912.             ctr++;
  1913.         }
  1914.     }
  1915.     while (ctr <= 19);
  1916.     }
  1917.     while (l != 0);
  1918.     do {
  1919.     j = *y - 2 + randint(3);
  1920.     k = *x - 2 + randint(3);
  1921.     if (in_bounds(j, k)) {
  1922.         cave_ptr = &cave[j][k];
  1923.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  1924.         place_monster(j, k, m, FALSE);
  1925.         summon = TRUE;
  1926.         i = 9;
  1927.         *y = j;
  1928.         *x = k;
  1929.         }
  1930.     }
  1931.     i++;
  1932.     }
  1933.     while (i <= 9);
  1934.     return (summon);
  1935. }
  1936.  
  1937. /* Summon reptiles */
  1938. int 
  1939. summon_reptile(y, x)
  1940. int *y, *x;
  1941. {
  1942.     register int        i, j, k;
  1943.     int                 l, m, ctr, summon;
  1944.     register cave_type *cave_ptr;
  1945.  
  1946.     i = 0;
  1947.     summon = FALSE;
  1948.     l = m_level[MAX_MONS_LEVEL];
  1949.     do {
  1950.     m = randint(l) - 1;
  1951.     ctr = 0;
  1952.     do {
  1953.         if (c_list[m].cchar == 'R' && !(c_list[m].cdefense & UNIQUE)) {
  1954.         ctr = 20;
  1955.         l = 0;
  1956.         } else {
  1957.         m++;
  1958.         if (m > l)
  1959.             ctr = 20;
  1960.         else
  1961.             ctr++;
  1962.         }
  1963.     }
  1964.     while (ctr <= 19);
  1965.     }
  1966.     while (l != 0);
  1967.     do {
  1968.     j = *y - 2 + randint(3);
  1969.     k = *x - 2 + randint(3);
  1970.     if (in_bounds(j, k)) {
  1971.         cave_ptr = &cave[j][k];
  1972.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  1973.         place_monster(j, k, m, FALSE);
  1974.         summon = TRUE;
  1975.         i = 9;
  1976.         *y = j;
  1977.         *x = k;
  1978.         }
  1979.     }
  1980.     i++;
  1981.     }
  1982.     while (i <= 9);
  1983.     return (summon);
  1984. }
  1985.  
  1986.  
  1987. /* As for summon dragon, but keys on character ~Decado */
  1988. int 
  1989. summon_spider(y, x)
  1990. int *y, *x;
  1991. {
  1992.     register int        i, j, k;
  1993.     int                 l, m, ctr, summon;
  1994.     register cave_type *cave_ptr;
  1995.  
  1996.     i = 0;
  1997.     summon = FALSE;
  1998.     l = m_level[MAX_MONS_LEVEL];
  1999.     do {
  2000.     m = randint(l) - 1;
  2001.     ctr = 0;
  2002.     do {
  2003.         if (c_list[m].cchar == 'S' && !(c_list[m].cdefense & UNIQUE)) {
  2004.         ctr = 20;
  2005.         l = 0;
  2006.         } else {
  2007.         m++;
  2008.         if (m > l)
  2009.             ctr = 20;
  2010.         else
  2011.             ctr++;
  2012.         }
  2013.     }
  2014.     while (ctr <= 19);
  2015.     }
  2016.     while (l != 0);
  2017.     do {
  2018.     j = *y - 2 + randint(3);
  2019.     k = *x - 2 + randint(3);
  2020.     if (in_bounds(j, k)) {
  2021.         cave_ptr = &cave[j][k];
  2022.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2023.         place_monster(j, k, m, FALSE);
  2024.         summon = TRUE;
  2025.         i = 9;
  2026.         *y = j;
  2027.         *x = k;
  2028.         }
  2029.     }
  2030.     i++;
  2031.     }
  2032.     while (i <= 9);
  2033.     return (summon);
  2034. }
  2035.  
  2036. /* As for summon dragon, but keys on character ~Decado */
  2037. int 
  2038. summon_angel(y, x)
  2039. int *y, *x;
  2040. {
  2041.     register int        i, j, k;
  2042.     int                 l, m, ctr, summon;
  2043.     register cave_type *cave_ptr;
  2044.  
  2045.     i = 0;
  2046.     summon = FALSE;
  2047.     l = m_level[MAX_MONS_LEVEL];
  2048.     do {
  2049.     m = randint(l) - 1;
  2050.     ctr = 0;
  2051.     do {
  2052.         if (c_list[m].cchar == 'A' && !(c_list[m].cdefense & UNIQUE)) {
  2053.         ctr = 20;
  2054.         l = 0;
  2055.         } else {
  2056.         m++;
  2057.         if (m > l)
  2058.             ctr = 20;
  2059.         else
  2060.             ctr++;
  2061.         }
  2062.     } while (ctr <= 19);
  2063.     }
  2064.     while (l != 0);
  2065.     do {
  2066.     j = *y - 2 + randint(3);
  2067.     k = *x - 2 + randint(3);
  2068.     if (in_bounds(j, k)) {
  2069.         cave_ptr = &cave[j][k];
  2070.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2071.         place_monster(j, k, m, FALSE);
  2072.         summon = TRUE;
  2073.         i = 9;
  2074.         *y = j;
  2075.         *x = k;
  2076.         }
  2077.     }
  2078.     i++;
  2079.     } while (i <= 9);
  2080.     return (summon);
  2081. }
  2082.  
  2083. /* Summon ants */
  2084. int 
  2085. summon_ant(y, x)
  2086. int *y, *x;
  2087. {
  2088.     register int        i, j, k;
  2089.     int                 l, m, ctr, summon;
  2090.     register cave_type *cave_ptr;
  2091.  
  2092.     i = 0;
  2093.     summon = FALSE;
  2094.     l = m_level[MAX_MONS_LEVEL];
  2095.     do {
  2096.     m = randint(l) - 1;
  2097.     ctr = 0;
  2098.     do {
  2099.         if (c_list[m].cchar == 'a' && !(c_list[m].cdefense & UNIQUE)) {
  2100.         ctr = 20;
  2101.         l = 0;
  2102.         } else {
  2103.         m++;
  2104.         if (m > l)
  2105.             ctr = 20;
  2106.         else
  2107.             ctr++;
  2108.         }
  2109.     }
  2110.     while (ctr <= 19);
  2111.     }
  2112.     while (l != 0);
  2113.     do {
  2114.     j = *y - 2 + randint(3);
  2115.     k = *x - 2 + randint(3);
  2116.     if (in_bounds(j, k)) {
  2117.         cave_ptr = &cave[j][k];
  2118.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2119.         place_monster(j, k, m, FALSE);
  2120.         summon = TRUE;
  2121.         i = 9;
  2122.         *y = j;
  2123.         *x = k;
  2124.         }
  2125.     }
  2126.     i++;
  2127.     }
  2128.     while (i <= 9);
  2129.     return (summon);
  2130. }
  2131.  
  2132. /* Summon uniques */
  2133. int 
  2134. summon_unique(y, x)
  2135. int *y, *x;
  2136. {
  2137.     register int        i, j, k;
  2138.     int                 l, m, ctr, summon;
  2139.     register cave_type *cave_ptr;
  2140.  
  2141.     i = 0;
  2142.     summon = FALSE;
  2143.     l = m_level[MAX_MONS_LEVEL];
  2144.     do {
  2145.     m = randint(l) - 1;
  2146.     ctr = 0;
  2147.     do {
  2148.         if (!(c_list[m].cchar == 'P') && (c_list[m].cdefense & UNIQUE)) {
  2149.         ctr = 20;
  2150.         l = 0;
  2151.         } else {
  2152.         m++;
  2153.         if (m > l)
  2154.             ctr = 20;
  2155.         else
  2156.             ctr++;
  2157.         }
  2158.     }
  2159.     while (ctr <= 19);
  2160.     }
  2161.     while (l != 0);
  2162.     do {
  2163.     j = *y - 2 + randint(3);
  2164.     k = *x - 2 + randint(3);
  2165.     if (in_bounds(j, k)) {
  2166.         cave_ptr = &cave[j][k];
  2167.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2168.         place_monster(j, k, m, FALSE);
  2169.         summon = TRUE;
  2170.         i = 9;
  2171.         *y = j;
  2172.         *x = k;
  2173.         }
  2174.     }
  2175.     i++;
  2176.     }
  2177.     while (i <= 9);
  2178.     return (summon);
  2179. }
  2180.  
  2181. /* Summon jabberwocks, for extra effect to the summon_unique spell */
  2182. int 
  2183. summon_jabberwock(y, x)
  2184. int *y, *x;
  2185. {
  2186.     register int        i, j, k;
  2187.     int                 l, m, ctr, summon;
  2188.     register cave_type *cave_ptr;
  2189.  
  2190.     i = 0;
  2191.     summon = FALSE;
  2192.     l = m_level[MAX_MONS_LEVEL];
  2193.     do {
  2194.     m = randint(l) - 1;
  2195.     ctr = 0;
  2196.     do {
  2197.         if (c_list[m].cchar == 'J' && !(c_list[m].cdefense & UNIQUE)) {
  2198.         ctr = 20;
  2199.         l = 0;
  2200.         } else {
  2201.         m++;
  2202.         if (m > l)
  2203.             ctr = 20;
  2204.         else
  2205.             ctr++;
  2206.         }
  2207.     }
  2208.     while (ctr <= 19);
  2209.     }
  2210.     while (l != 0);
  2211.     do {
  2212.     j = *y - 2 + randint(3);
  2213.     k = *x - 2 + randint(3);
  2214.     if (in_bounds(j, k)) {
  2215.         cave_ptr = &cave[j][k];
  2216.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2217.         place_monster(j, k, m, FALSE);
  2218.         summon = TRUE;
  2219.         i = 9;
  2220.         *y = j;
  2221.         *x = k;
  2222.         }
  2223.     }
  2224.     i++;
  2225.     }
  2226.     while (i <= 9);
  2227.     return (summon);
  2228. }
  2229.  
  2230. /* Summon greater undead */
  2231. int 
  2232. summon_gundead(y, x)
  2233. int *y, *x;
  2234. {
  2235.     register int        i, j, k;
  2236.     int                 l, m, ctr, summon;
  2237.     register cave_type *cave_ptr;
  2238.  
  2239.     i = 0;
  2240.     summon = FALSE;
  2241.     l = m_level[MAX_MONS_LEVEL];
  2242.     do {
  2243.     m = randint(l) - 1;
  2244.     ctr = 0;
  2245.     do {
  2246.         if ((c_list[m].cchar == 'L') || (c_list[m].cchar == 'V')
  2247.         || (c_list[m].cchar == 'W')) {
  2248.         ctr = 20;
  2249.         l = 0;
  2250.         } else {
  2251.         m++;
  2252.         if (m > l)
  2253.             ctr = 20;
  2254.         else
  2255.             ctr++;
  2256.         }
  2257.     }
  2258.     while (ctr <= 19);
  2259.     }
  2260.     while (l != 0);
  2261.     do {
  2262.     j = *y - 2 + randint(3);
  2263.     k = *x - 2 + randint(3);
  2264.     if (in_bounds(j, k)) {
  2265.         cave_ptr = &cave[j][k];
  2266.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2267.         place_monster(j, k, m, FALSE);
  2268.         summon = TRUE;
  2269.         i = 9;
  2270.         *y = j;
  2271.         *x = k;
  2272.         }
  2273.     }
  2274.     i++;
  2275.     }
  2276.     while (i <= 9);
  2277.     return (summon);
  2278. }
  2279.  
  2280. /* Summon ancient dragons */
  2281. int 
  2282. summon_ancientd(y, x)
  2283. int *y, *x;
  2284. {
  2285.     register int        i, j, k;
  2286.     int                 l, m, ctr, summon;
  2287.     register cave_type *cave_ptr;
  2288.  
  2289.     i = 0;
  2290.     summon = FALSE;
  2291.     l = m_level[MAX_MONS_LEVEL];
  2292.     do {
  2293.     m = randint(l) - 1;
  2294.     ctr = 0;
  2295.     do {
  2296.         if (c_list[m].cchar == 'D') {
  2297.         ctr = 20;
  2298.         l = 0;
  2299.         } else {
  2300.         m++;
  2301.         if (m > l)
  2302.             ctr = 20;
  2303.         else
  2304.             ctr++;
  2305.         }
  2306.     }
  2307.     while (ctr <= 19);
  2308.     }
  2309.     while (l != 0);
  2310.     do {
  2311.     j = *y - 2 + randint(3);
  2312.     k = *x - 2 + randint(3);
  2313.     if (in_bounds(j, k)) {
  2314.         cave_ptr = &cave[j][k];
  2315.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2316.         place_monster(j, k, m, FALSE);
  2317.         summon = TRUE;
  2318.         i = 9;
  2319.         *y = j;
  2320.         *x = k;
  2321.         }
  2322.     }
  2323.     i++;
  2324.     }
  2325.     while (i <= 9);
  2326.     return (summon);
  2327. }
  2328.  
  2329. /* As for summon hound, but keys on character ~Decado */
  2330. int 
  2331. summon_hound(y, x)
  2332. int *y, *x;
  2333. {
  2334.     register int        i, j, k;
  2335.     int                 l, m, ctr, summon;
  2336.     register cave_type *cave_ptr;
  2337.  
  2338.     i = 0;
  2339.     summon = FALSE;
  2340.     l = m_level[MAX_MONS_LEVEL];
  2341.     do {
  2342.     m = randint(l) - 1;
  2343.     ctr = 0;
  2344.     do {
  2345.         if ((c_list[m].cchar == 'C' || c_list[m].cchar == 'Z')
  2346.         && !(c_list[m].cdefense & UNIQUE)) {
  2347.         ctr = 20;
  2348.         l = 0;
  2349.         } else {
  2350.         m++;
  2351.         if (m > l)
  2352.             ctr = 20;
  2353.         else
  2354.             ctr++;
  2355.         }
  2356.     }
  2357.     while (ctr <= 19);
  2358.     }
  2359.     while (l != 0);
  2360.     do {
  2361.     j = *y - 2 + randint(3);
  2362.     k = *x - 2 + randint(3);
  2363.     if (in_bounds(j, k)) {
  2364.         cave_ptr = &cave[j][k];
  2365.         if (cave_ptr->fval <= MAX_OPEN_SPACE && (cave_ptr->cptr == 0)) {
  2366.         place_monster(j, k, m, FALSE);
  2367.         summon = TRUE;
  2368.         i = 9;
  2369.         *y = j;
  2370.         *x = k;
  2371.         }
  2372.     }
  2373.     i++;
  2374.     }
  2375.     while (i <= 9);
  2376.     return (summon);
  2377. }
  2378.  
  2379. /* Place a sleepy jelly at the required coordinates ~Ludwig */
  2380. int 
  2381. summon_jelly(y, x)
  2382. int *y, *x;
  2383. {
  2384.     int l, m, summon;
  2385.  
  2386.     summon = FALSE;
  2387.     l = m_level[MAX_MONS_LEVEL];
  2388.     do {
  2389.     m = randint(l) - 1;
  2390.     if (c_list[m].cchar == 'J') {
  2391.         summon = TRUE;
  2392.         place_monster(*y, *x, m, TRUE);
  2393.     }
  2394.     } while (!summon);
  2395.     return (summon);
  2396. }
  2397.  
  2398. /* If too many objects on floor level, delete some of them */
  2399. static void 
  2400. compact_objects()
  2401. {
  2402.     register int        i, j;
  2403.     int                 ctr, cur_dis, chance;
  2404.     register cave_type *cave_ptr;
  2405.  
  2406.     msg_print("Compacting objects...");
  2407.  
  2408.     ctr = 0;
  2409.     cur_dis = 66;
  2410.     do {
  2411.     for (i = 0; i < cur_height; i++)
  2412.         for (j = 0; j < cur_width; j++) {
  2413.         cave_ptr = &cave[i][j];
  2414.         if ((cave_ptr->tptr != 0)
  2415.             && (distance(i, j, char_row, char_col) > cur_dis)) {
  2416.             switch (t_list[cave_ptr->tptr].tval) {
  2417.               case TV_VIS_TRAP:
  2418.             chance = 15;
  2419.             break;
  2420.               case TV_INVIS_TRAP:
  2421.               case TV_RUBBLE:
  2422.               case TV_OPEN_DOOR:
  2423.               case TV_CLOSED_DOOR:
  2424.             chance = 5;
  2425.             break;
  2426.               case TV_UP_STAIR:
  2427.               case TV_DOWN_STAIR:
  2428.               case TV_STORE_DOOR:
  2429.             chance = 0;
  2430.             break;
  2431.               case TV_SECRET_DOOR:    /* secret doors */
  2432.             chance = 3;
  2433.             break;
  2434.               default:
  2435.             if ((t_list[cave_ptr->tptr].tval >= TV_MIN_WEAR) &&
  2436.                 (t_list[cave_ptr->tptr].tval <= TV_MAX_WEAR) &&
  2437.                 (t_list[cave_ptr->tptr].flags2 & TR_ARTIFACT))
  2438.                 chance = 0;    /* don't compact artifacts -CFT */
  2439.             else
  2440.                 chance = 10;
  2441.             }
  2442.             if (randint(100) <= chance) {
  2443.             (void)delete_object(i, j);
  2444.             ctr++;
  2445.             }
  2446.         }
  2447.         }
  2448.     if (ctr == 0)
  2449.         cur_dis -= 6;
  2450.     }
  2451.     while (ctr <= 0);
  2452.     if (cur_dis < 66)
  2453.     prt_map();
  2454. }
  2455.  
  2456. /* Gives pointer to next free space            -RAK-     */
  2457. int 
  2458. popt()
  2459. {
  2460.     if (tcptr == MAX_TALLOC)
  2461.     compact_objects();
  2462.     return (tcptr++);
  2463. }
  2464.  
  2465.  
  2466. /* Pushs a record back onto free space list        -RAK-     */
  2467. /*
  2468.  * Delete_object() should always be called instead, unless the object in
  2469.  * question is not in the dungeon, e.g. in store1.c and files.c 
  2470.  */
  2471. void 
  2472. pusht(my_x)
  2473. int my_x;
  2474. {
  2475.     int16        x = (int16) my_x;
  2476.     register int i, j;
  2477.  
  2478.     if (x != tcptr - 1) {
  2479.     t_list[x] = t_list[tcptr - 1];
  2480.  
  2481.     /* must change the tptr in the cave of the object just moved */
  2482.     for (i = 0; i < cur_height; i++)
  2483.         for (j = 0; j < cur_width; j++)
  2484.         if (cave[i][j].tptr == tcptr - 1)
  2485.             cave[i][j].tptr = x;
  2486.     }
  2487.     tcptr--;
  2488.     invcopy(&t_list[tcptr], OBJ_NOTHING);
  2489. }
  2490.  
  2491.  
  2492. /* Boolean : is object enchanted      -RAK- */
  2493. int 
  2494. magik(chance)
  2495. int chance;
  2496. {
  2497.     if (randint(100) <= chance)
  2498.     return (TRUE);
  2499.     else
  2500.     return (FALSE);
  2501. }
  2502.  
  2503.  
  2504. /* Enchant a bonus based on degree desired -RAK- */
  2505. /*
  2506.  * Lets just change this to make sense.  Now it goes from base to limit,
  2507.  * roughly proportional to the level.... -CWS 
  2508.  */
  2509.  
  2510. int 
  2511. m_bonus(base, limit, level)
  2512. int base, limit, level;
  2513. {
  2514.     register int x, stand_dev, tmp, diff = limit - base;
  2515.  
  2516. /* standard deviation twice as wide at bottom of Angband as top */
  2517.     stand_dev = (OBJ_STD_ADJ * (1 + level / 100)) + OBJ_STD_MIN;
  2518. /* check for level > max_std to check for overflow... */
  2519.     if (stand_dev > 40)
  2520.     stand_dev = 40;
  2521. /* abs may be a macro, don't call it with randnor as a parameter */
  2522.     tmp = randnor(0, stand_dev);
  2523.     x = (tmp * diff / 150) + (level * limit / 200) + base;
  2524.     if (x < base)
  2525.     return (base);
  2526.     else
  2527.     return (x);
  2528. }
  2529.  
  2530. int 
  2531. unique_weapon(t_ptr)
  2532. inven_type *t_ptr;
  2533. {
  2534.     const char *name;
  2535.  
  2536.     if (be_nasty)
  2537.     return 0;
  2538.     name = object_list[t_ptr->index].name;
  2539.     if (!stricmp("& Longsword", name)) {
  2540.     switch (randint(15)) {
  2541.       case 1:
  2542.         if (RINGIL)
  2543.         return 0;
  2544.         if (wizard || peek)
  2545.         msg_print("Ringil");
  2546.         else
  2547.         good_item_flag = TRUE;
  2548.         t_ptr->name2 = SN_RINGIL;
  2549.         t_ptr->tohit = 22;
  2550.         t_ptr->todam = 25;
  2551.         t_ptr->damage[0] = 4;
  2552.         t_ptr->flags = (TR_SEE_INVIS | TR_SLAY_UNDEAD | TR_SLAY_EVIL | TR_REGEN |
  2553.              TR_SPEED | TR_RES_COLD | TR_FROST_BRAND | TR_FREE_ACT |
  2554.                 TR_SLOW_DIGEST);
  2555.         t_ptr->flags2 |= (TR_SLAY_DEMON | TR_SLAY_TROLL | TR_LIGHT | TR_ACTIVATE
  2556.                   | TR_RES_LT | TR_ARTIFACT);
  2557.         t_ptr->p1 = 1;
  2558.         t_ptr->cost = 300000L;
  2559.         RINGIL = 1;
  2560.         return 1;
  2561.       case 2:
  2562.       case 3:
  2563.       case 4:
  2564.         if (ANDURIL)
  2565.         return 0;
  2566.         if (wizard || peek)
  2567.         msg_print("Anduril");
  2568.         else
  2569.         good_item_flag = TRUE;
  2570.         t_ptr->name2 = SN_ANDURIL;
  2571.         t_ptr->tohit = 10;
  2572.         t_ptr->todam = 15;
  2573.         t_ptr->flags = (TR_SEE_INVIS | TR_SLAY_EVIL | TR_FREE_ACT |
  2574.              TR_SUST_STAT | TR_STR | TR_RES_FIRE | TR_FLAME_TONGUE);
  2575.         t_ptr->flags2 |= (TR_SLAY_TROLL | TR_ACTIVATE | TR_SLAY_ORC | TR_ARTIFACT);
  2576.         t_ptr->p1 = 4;
  2577.         t_ptr->toac = 5;
  2578.         t_ptr->cost = 80000L;
  2579.         ANDURIL = 1;
  2580.         return 1;
  2581.       case 5:
  2582.       case 6:
  2583.       case 7:
  2584.       case 8:
  2585.         if (ANGUIREL)
  2586.         return 0;
  2587.         if (wizard || peek)
  2588.         msg_print("Anguirel");
  2589.         else
  2590.         good_item_flag = TRUE;
  2591.         t_ptr->name2 = SN_ANGUIREL;
  2592.         t_ptr->tohit = 8;
  2593.         t_ptr->todam = 12;
  2594.         t_ptr->flags = (TR_SEE_INVIS | TR_SLAY_EVIL | TR_FREE_ACT | TR_RES_LIGHT
  2595.                 | TR_STR | TR_CON);
  2596.         t_ptr->flags2 |= (TR_ARTIFACT |
  2597.                TR_LIGHTNING | TR_LIGHT | TR_SLAY_DEMON | TR_RES_LT);
  2598.         t_ptr->p1 = 2;
  2599.         t_ptr->cost = 40000L;
  2600.         ANGUIREL = 1;
  2601.         return 1;
  2602.       default:
  2603.         if (ELVAGIL)
  2604.         return 0;
  2605.         if (wizard || peek)
  2606.         msg_print("Elvagil");
  2607.         else
  2608.         good_item_flag = TRUE;
  2609.         t_ptr->name2 = SN_ELVAGIL;
  2610.         t_ptr->ident |= ID_NOSHOW_TYPE;
  2611.         t_ptr->tohit = 2;
  2612.         t_ptr->todam = 7;
  2613.         t_ptr->flags |= (TR_SEE_INVIS | TR_CHR | TR_DEX | TR_STEALTH | TR_FFALL);
  2614.         t_ptr->flags2 |= (TR_SLAY_TROLL | TR_SLAY_ORC | TR_ARTIFACT);
  2615.         t_ptr->p1 = 2;
  2616.         t_ptr->cost = 30000L;
  2617.         ELVAGIL = 1;
  2618.         return 1;
  2619.     }
  2620.     } else if (!stricmp("& Two-Handed Sword", name)) {
  2621.     switch (randint(8)) {
  2622.       case 1:
  2623.       case 2:
  2624.         if (GURTHANG)
  2625.         return 0;
  2626.         if (wizard || peek)
  2627.         msg_print("Gurthang");
  2628.         else
  2629.         good_item_flag = TRUE;
  2630.         t_ptr->name2 = SN_GURTHANG;
  2631.         t_ptr->tohit = 13;
  2632.         t_ptr->todam = 17;
  2633.         t_ptr->flags = (TR_REGEN | TR_SLAY_X_DRAGON | TR_STR |
  2634.                 TR_FREE_ACT | TR_SLOW_DIGEST);
  2635.         t_ptr->flags2 |= (TR_SLAY_TROLL | TR_ARTIFACT);
  2636.         t_ptr->p1 = 2;
  2637.         t_ptr->cost = 100000L;
  2638.         GURTHANG = 1;
  2639.         return 1;
  2640.       case 3:
  2641.         if (ZARCUTHRA)
  2642.         return 0;
  2643.         if (randint(3) > 1)
  2644.         return 0;
  2645.         if (wizard || peek)
  2646.         msg_print("Zarcuthra");
  2647.         else
  2648.         good_item_flag = TRUE;
  2649.         t_ptr->name2 = SN_ZARCUTHRA;
  2650.         t_ptr->ident |= ID_NOSHOW_TYPE;
  2651.         t_ptr->tohit = 19;
  2652.         t_ptr->todam = 21;
  2653.         t_ptr->flags = (TR_SLAY_X_DRAGON | TR_STR | TR_SLAY_EVIL | TR_SLAY_ANIMAL |
  2654.           TR_SLAY_UNDEAD | TR_AGGRAVATE | TR_CHR | TR_FLAME_TONGUE |
  2655.           TR_SEE_INVIS | TR_RES_FIRE | TR_FREE_ACT | TR_INFRA);
  2656.         t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_TROLL | TR_SLAY_ORC | TR_SLAY_GIANT
  2657.                   | TR_SLAY_DEMON | TR_RES_CHAOS);
  2658.         t_ptr->p1 = 4;
  2659.         t_ptr->damage[0] = 6;
  2660.         t_ptr->damage[1] = 4;
  2661.         t_ptr->cost = 200000L;
  2662.         ZARCUTHRA = 1;
  2663.         return 1;
  2664.       default:
  2665.         if (MORMEGIL)
  2666.         return 0;
  2667.         if (wizard || peek)
  2668.         msg_print("Mormegil");
  2669.         else
  2670.         good_item_flag = TRUE;
  2671.         t_ptr->name2 = SN_MORMEGIL;
  2672.         t_ptr->tohit = -40;
  2673.         t_ptr->todam = -60;
  2674.         t_ptr->flags = (TR_SPEED | TR_AGGRAVATE | TR_CURSED);
  2675.         t_ptr->flags2 |= (TR_ARTIFACT);
  2676.         t_ptr->p1 = -1;
  2677.         t_ptr->toac = -50;
  2678.         t_ptr->cost = 10000L;
  2679.         MORMEGIL = 1;
  2680.         return 1;
  2681.     }
  2682.     } else if (!stricmp("& Broadsword", name)) {
  2683.     switch (randint(12)) {
  2684.       case 1:
  2685.       case 2:
  2686.         if (ARUNRUTH)
  2687.         return 0;
  2688.         if (wizard || peek)
  2689.         msg_print("Arunruth");
  2690.         else
  2691.         good_item_flag = TRUE;
  2692.         t_ptr->name2 = SN_ARUNRUTH;
  2693.         t_ptr->tohit = 20;
  2694.         t_ptr->todam = 12;
  2695.         t_ptr->damage[0] = 3;
  2696.         t_ptr->flags = (TR_FFALL | TR_DEX |
  2697.                 TR_FREE_ACT | TR_SLOW_DIGEST);
  2698.         t_ptr->flags2 |= (TR_SLAY_DEMON | TR_SLAY_ORC | TR_ACTIVATE | TR_ARTIFACT);
  2699.         t_ptr->p1 = 4;
  2700.         t_ptr->cost = 50000L;
  2701.         ARUNRUTH = 1;
  2702.         return 1;
  2703.       case 3:
  2704.       case 4:
  2705.       case 5:
  2706.       case 6:
  2707.         if (GLAMDRING)
  2708.         return 0;
  2709.         if (wizard || peek)
  2710.         msg_print("Glamdring");
  2711.         else
  2712.         good_item_flag = TRUE;
  2713.         t_ptr->name2 = SN_GLAMDRING;
  2714.         t_ptr->tohit = 10;
  2715.         t_ptr->todam = 15;
  2716.         t_ptr->flags = (TR_SLAY_EVIL | TR_SLOW_DIGEST | TR_SEARCH | TR_FLAME_TONGUE |
  2717.                 TR_RES_FIRE);
  2718.         t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_ORC | TR_LIGHT | TR_RES_LT);
  2719.         t_ptr->p1 = 3;
  2720.         t_ptr->cost = 40000L;
  2721.         GLAMDRING = 1;
  2722.         return 1;
  2723.       case 7:
  2724.         if (AEGLIN)
  2725.         return 0;
  2726.         if (wizard || peek)
  2727.         msg_print("Aeglin");
  2728.         else
  2729.         good_item_flag = TRUE;
  2730.         t_ptr->name2 = SN_AEGLIN;
  2731.         t_ptr->tohit = 12;
  2732.         t_ptr->todam = 16;
  2733.         t_ptr->flags = (TR_SLOW_DIGEST | TR_SEARCH | TR_RES_LIGHT);
  2734.         t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_ORC | TR_LIGHT | TR_LIGHTNING);
  2735.         t_ptr->p1 = 4;
  2736.         t_ptr->cost = 45000L;
  2737.         AEGLIN = 1;
  2738.         return 1;
  2739.       default:
  2740.         if (ORCRIST)
  2741.         return 0;
  2742.         if (wizard || peek)
  2743.         msg_print("Orcrist");
  2744.         else
  2745.         good_item_flag = TRUE;
  2746.         t_ptr->name2 = SN_ORCRIST;
  2747.         t_ptr->tohit = 10;
  2748.         t_ptr->todam = 15;
  2749.         t_ptr->flags = (TR_SLAY_EVIL | TR_SLOW_DIGEST | TR_STEALTH | TR_FROST_BRAND |
  2750.                 TR_RES_COLD);
  2751.         t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_ORC | TR_LIGHT);
  2752.         t_ptr->p1 = 3;
  2753.         t_ptr->cost = 40000L;
  2754.         ORCRIST = 1;
  2755.         return 1;
  2756.     }
  2757.     } else if (!stricmp("& Bastard Sword", name)) {
  2758.     if (CALRIS)
  2759.         return 0;
  2760.     if (wizard || peek)
  2761.         msg_print("Calris");
  2762.     else
  2763.         good_item_flag = TRUE;
  2764.     t_ptr->name2 = SN_CALRIS;
  2765.     t_ptr->tohit = -20;
  2766.     t_ptr->todam = 20;
  2767.     t_ptr->damage[0] = 3;
  2768.     t_ptr->damage[1] = 7;
  2769.     t_ptr->flags = (TR_SLAY_X_DRAGON | TR_CON | TR_AGGRAVATE |
  2770.             TR_CURSED | TR_SLAY_EVIL);
  2771.     t_ptr->flags2 |= (TR_SLAY_DEMON | TR_SLAY_TROLL | TR_RES_DISENCHANT
  2772.               | TR_ARTIFACT);
  2773.     t_ptr->p1 = 5;
  2774.     t_ptr->cost = 100000L;
  2775.     CALRIS = 1;
  2776.     return 1;
  2777.     } else if (!stricmp("& Main Gauche", name)) {
  2778.     if (randint(4) > 1)
  2779.         return 0;
  2780.     if (MAEDHROS)
  2781.         return 0;
  2782.     if (wizard || peek)
  2783.         msg_print("Maedhros");
  2784.     else
  2785.         good_item_flag = TRUE;
  2786.     t_ptr->name2 = SN_MAEDHROS;
  2787.     t_ptr->tohit = 12;
  2788.     t_ptr->todam = 15;
  2789.     t_ptr->damage[0] = 2;
  2790.     t_ptr->damage[1] = 6;
  2791.     t_ptr->flags = (TR_DEX | TR_INT | TR_FREE_ACT | TR_SEE_INVIS);
  2792.     t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_GIANT | TR_SLAY_TROLL);
  2793.     t_ptr->p1 = 3;
  2794.     t_ptr->cost = 20000L;
  2795.     MAEDHROS = 1;
  2796.     return 1;
  2797.     } else if (!stricmp("& Glaive", name)) {
  2798.     if (randint(3) > 1)
  2799.         return 0;
  2800.     if (PAIN)
  2801.         return 0;
  2802.     if (wizard || peek)
  2803.         msg_print("Pain!");
  2804.     else
  2805.         good_item_flag = TRUE;
  2806.     t_ptr->name2 = SN_PAIN;
  2807.     t_ptr->tohit = 0;
  2808.     t_ptr->todam = 30;
  2809.     t_ptr->damage[0] = 10;
  2810.     t_ptr->damage[1] = 6;
  2811.     t_ptr->flags2 |= (TR_ARTIFACT);
  2812.     t_ptr->cost = 50000L;
  2813.     PAIN = 1;
  2814.     return 1;
  2815.     } else if (!stricmp("& Halberd", name)) {
  2816.     if (OSONDIR)
  2817.         return 0;
  2818.     if (wizard || peek)
  2819.         msg_print("Osondir");
  2820.     else
  2821.         good_item_flag = TRUE;
  2822.     t_ptr->name2 = SN_OSONDIR;
  2823.     t_ptr->tohit = 6;
  2824.     t_ptr->todam = 9;
  2825.     t_ptr->flags = (TR_FLAME_TONGUE | TR_SLAY_UNDEAD | TR_RES_FIRE |
  2826.             TR_FFALL | TR_CHR | TR_SEE_INVIS);
  2827.     t_ptr->flags2 |= (TR_ARTIFACT | TR_RES_SOUND | TR_SLAY_GIANT);
  2828.     t_ptr->p1 = 3;
  2829.     t_ptr->cost = 22000L;
  2830.     OSONDIR = 1;
  2831.     return 1;
  2832.     } else if (!stricmp("& Lucerne Hammer", name)) {
  2833.     if (randint(2) > 1)
  2834.         return 0;
  2835.     if (TURMIL)
  2836.         return 0;
  2837.     if (wizard || peek)
  2838.         msg_print("Turmil");
  2839.     else
  2840.         good_item_flag = TRUE;
  2841.     t_ptr->name2 = SN_TURMIL;
  2842.     t_ptr->ident |= ID_NOSHOW_TYPE;
  2843.     t_ptr->tohit = 10;
  2844.     t_ptr->todam = 6;
  2845.     t_ptr->flags = (TR_WIS | TR_REGEN | TR_FROST_BRAND | TR_RES_COLD | TR_INFRA);
  2846.     t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_ORC | TR_LIGHT |
  2847.               TR_ACTIVATE | TR_RES_LT);
  2848.     t_ptr->p1 = 4;
  2849.     t_ptr->cost = 30000L;
  2850.     t_ptr->toac = 8;
  2851.     TURMIL = 1;
  2852.     return 1;
  2853.     } else if (!stricmp("& Pike", name)) {
  2854.     if (randint(2) > 1)
  2855.         return 0;
  2856.     if (TIL)
  2857.         return 0;
  2858.     if (wizard || peek)
  2859.         msg_print("Til-i-arc");
  2860.     else
  2861.         good_item_flag = TRUE;
  2862.     t_ptr->name2 = SN_TIL;
  2863.     t_ptr->tohit = 10;
  2864.     t_ptr->todam = 12;
  2865.     t_ptr->toac = 10;
  2866.     t_ptr->flags = (TR_FROST_BRAND | TR_FLAME_TONGUE | TR_RES_FIRE | TR_RES_COLD |
  2867.             TR_SLOW_DIGEST | TR_INT | TR_SUST_STAT);
  2868.     t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_DEMON | TR_SLAY_GIANT | TR_SLAY_TROLL);
  2869.     t_ptr->p1 = 2;
  2870.     t_ptr->cost = 32000L;
  2871.     TIL = 1;
  2872.     return 1;
  2873.     } else if (!stricmp("& Mace of Disruption", name)) {
  2874.     if (randint(5) > 1)
  2875.         return 0;
  2876.     if (DEATHWREAKER)
  2877.         return 0;
  2878.     if (wizard || peek)
  2879.         msg_print("Deathwreaker");
  2880.     else
  2881.         good_item_flag = TRUE;
  2882.     t_ptr->name2 = SN_DEATHWREAKER;
  2883.     t_ptr->tohit = 18;
  2884.     t_ptr->todam = 18;
  2885.     t_ptr->damage[1] = 12;
  2886.     t_ptr->flags = (TR_STR | TR_FLAME_TONGUE | TR_SLAY_EVIL | TR_SLAY_DRAGON |
  2887.            TR_SLAY_ANIMAL | TR_TUNNEL | TR_AGGRAVATE | TR_RES_FIRE);
  2888.     t_ptr->flags2 |= (TR_ARTIFACT | TR_IM_FIRE | TR_RES_CHAOS
  2889.               | TR_RES_DISENCHANT | TR_RES_DARK);
  2890.     t_ptr->p1 = 6;
  2891.     t_ptr->cost = 400000L;
  2892.     DEATHWREAKER = 1;
  2893.     return 1;
  2894.     } else if (!stricmp("& Scythe", name)) {
  2895.     if (AVAVIR)
  2896.         return 0;
  2897.     if (wizard || peek)
  2898.         msg_print("Avavir");
  2899.     else
  2900.         good_item_flag = TRUE;
  2901.     t_ptr->name2 = SN_AVAVIR;
  2902.     t_ptr->tohit = 8;
  2903.     t_ptr->todam = 8;
  2904.     t_ptr->toac = 10;
  2905.     t_ptr->flags = (TR_DEX | TR_CHR | TR_FREE_ACT | TR_RES_FIRE | TR_RES_COLD |
  2906.             TR_SEE_INVIS | TR_FLAME_TONGUE | TR_FROST_BRAND);
  2907.     t_ptr->flags2 |= (TR_ARTIFACT | TR_LIGHT | TR_ACTIVATE | TR_RES_LT);
  2908.     t_ptr->p1 = 3;
  2909.     t_ptr->cost = 18000L;
  2910.     AVAVIR = 1;
  2911.     return 1;
  2912.     } else if (!stricmp("& Mace", name)) {
  2913.     if (randint(2) > 1)
  2914.         return 0;
  2915.     if (TARATOL)
  2916.         return 0;
  2917.     if (wizard || peek)
  2918.         msg_print("Taratol");
  2919.     else
  2920.         good_item_flag = TRUE;
  2921.     t_ptr->name2 = SN_TARATOL;
  2922.     t_ptr->tohit = 12;
  2923.     t_ptr->todam = 12;
  2924.     t_ptr->weight = 200;
  2925.     t_ptr->damage[1] = 7;
  2926.     t_ptr->flags = (TR_SLAY_X_DRAGON | TR_RES_LIGHT);
  2927.     t_ptr->flags2 |= (TR_ARTIFACT | TR_LIGHTNING | TR_ACTIVATE | TR_RES_DARK);
  2928.     t_ptr->cost = 20000L;
  2929.     TARATOL = 1;
  2930.     return 1;
  2931.     } else if (!stricmp("& Lance", name)) {
  2932.     if (randint(3) > 1)
  2933.         return 0;
  2934.     if (EORLINGAS)
  2935.         return 0;
  2936.     if (wizard || peek)
  2937.         msg_print("Lance of Eorlingas");
  2938.     else
  2939.         good_item_flag = TRUE;
  2940.     t_ptr->name2 = SN_EORLINGAS;
  2941.     t_ptr->tohit = 3;
  2942.     t_ptr->todam = 21;
  2943.     t_ptr->weight = 360;
  2944.     t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_EVIL | TR_DEX);
  2945.     t_ptr->flags2 |= (TR_SLAY_TROLL | TR_SLAY_ORC | TR_ARTIFACT);
  2946.     t_ptr->p1 = 2;
  2947.     t_ptr->damage[1] = 12;
  2948.     t_ptr->cost = 55000L;
  2949.     EORLINGAS = 1;
  2950.     return 1;
  2951.     } else if (!stricmp("& Broad Axe", name)) {
  2952.     if (BARUKKHELED)
  2953.         return 0;
  2954.     if (wizard || peek)
  2955.         msg_print("Barukkheled");
  2956.     else
  2957.         good_item_flag = TRUE;
  2958.     t_ptr->name2 = SN_BARUKKHELED;
  2959.     t_ptr->tohit = 13;
  2960.     t_ptr->todam = 19;
  2961.     t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_EVIL | TR_CON);
  2962.     t_ptr->flags2 |= (TR_SLAY_ORC | TR_SLAY_TROLL | TR_SLAY_GIANT | TR_ARTIFACT);
  2963.     t_ptr->p1 = 3;
  2964.     t_ptr->cost = 50000L;
  2965.     BARUKKHELED = 1;
  2966.     return 1;
  2967.     } else if (!stricmp("& Trident", name)) {
  2968.     switch (randint(3)) {
  2969.       case 1:
  2970.       case 2:
  2971.         if (randint(3) > 1)
  2972.         return 0;
  2973.         if (WRATH)
  2974.         return 0;
  2975.         if (wizard || peek)
  2976.         msg_print("Wrath");
  2977.         else
  2978.         good_item_flag = TRUE;
  2979.         t_ptr->name2 = SN_WRATH;
  2980.         t_ptr->tohit = 16;
  2981.         t_ptr->todam = 18;
  2982.         t_ptr->weight = 300;
  2983.         t_ptr->damage[0] = 3;
  2984.         t_ptr->damage[1] = 9;
  2985.         t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_EVIL | TR_STR | TR_DEX |
  2986.                  TR_SLAY_UNDEAD);
  2987.         t_ptr->flags2 |= (TR_RES_DARK | TR_RES_LT | TR_ARTIFACT | TR_BLESS_BLADE);
  2988.         t_ptr->p1 = 2;
  2989.         t_ptr->cost = 90000L;
  2990.         WRATH = 1;
  2991.         return 1;
  2992.       case 3:
  2993.         if (randint(4) > 1)
  2994.         return 0;
  2995.         if (ULMO)
  2996.         return 0;
  2997.         if (wizard || peek)
  2998.         msg_print("Ulmo");
  2999.         else
  3000.         good_item_flag = TRUE;
  3001.         t_ptr->name2 = SN_ULMO;
  3002.         t_ptr->tohit = 15;
  3003.         t_ptr->todam = 19;
  3004.         t_ptr->damage[0] = 4;
  3005.         t_ptr->damage[1] = 10;
  3006.         t_ptr->flags = (TR_SEE_INVIS | TR_FREE_ACT | TR_DEX | TR_REGEN |
  3007.                 TR_SLOW_DIGEST | TR_SLAY_ANIMAL | TR_SLAY_DRAGON |
  3008.                 TR_RES_ACID);
  3009.         t_ptr->flags2 |= (TR_IM_ACID | TR_HOLD_LIFE | TR_ACTIVATE
  3010.                 | TR_RES_NETHER | TR_ARTIFACT | TR_BLESS_BLADE);
  3011.         t_ptr->p1 = 4;
  3012.         t_ptr->cost = 120000L;
  3013.         ULMO = 1;
  3014.         return 1;
  3015.     }
  3016.     } else if (!stricmp("& Scimitar", name)) {
  3017.     if (HARADEKKET)
  3018.         return 0;
  3019.     if (wizard || peek)
  3020.         msg_print("Haradekket");
  3021.     else
  3022.         good_item_flag = TRUE;
  3023.     t_ptr->name2 = SN_HARADEKKET;
  3024.     t_ptr->tohit = 9;
  3025.     t_ptr->todam = 11;
  3026.     t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_EVIL | TR_DEX | TR_SLAY_UNDEAD
  3027.              | TR_SLAY_ANIMAL);
  3028.     t_ptr->flags2 |= (TR_ARTIFACT | TR_ATTACK_SPD);
  3029.     t_ptr->p1 = 2;
  3030.     t_ptr->cost = 30000L;
  3031.     HARADEKKET = 1;
  3032.     return 1;
  3033.     } else if (!stricmp("& Lochaber Axe", name)) {
  3034.     if (MUNDWINE)
  3035.         return 0;
  3036.     if (wizard || peek)
  3037.         msg_print("Mundwine");
  3038.     else
  3039.         good_item_flag = TRUE;
  3040.     t_ptr->name2 = SN_MUNDWINE;
  3041.     t_ptr->tohit = 12;
  3042.     t_ptr->todam = 17;
  3043.     t_ptr->flags |= (TR_SLAY_EVIL | TR_RES_FIRE | TR_RES_COLD
  3044.              | TR_RES_LIGHT | TR_RES_ACID);
  3045.     t_ptr->flags2 |= (TR_ARTIFACT);
  3046.     t_ptr->cost = 30000L;
  3047.     MUNDWINE = 1;
  3048.     return 1;
  3049.     } else if (!stricmp("& Cutlass", name)) {
  3050.     if (GONDRICAM)
  3051.         return 0;
  3052.     if (wizard || peek)
  3053.         msg_print("Gondricam");
  3054.     else
  3055.         good_item_flag = TRUE;
  3056.     t_ptr->name2 = SN_GONDRICAM;
  3057.     t_ptr->ident |= ID_NOSHOW_TYPE;
  3058.     t_ptr->tohit = 10;
  3059.     t_ptr->todam = 11;
  3060.     t_ptr->flags |= (TR_SEE_INVIS | TR_FFALL | TR_REGEN | TR_STEALTH | TR_RES_FIRE |
  3061.              TR_RES_COLD | TR_RES_ACID | TR_RES_LIGHT | TR_DEX);
  3062.     t_ptr->flags2 |= (TR_ARTIFACT);
  3063.     t_ptr->p1 = 3;
  3064.     t_ptr->cost = 28000L;
  3065.     GONDRICAM = 1;
  3066.     return 1;
  3067.     } else if (!stricmp("& Sabre", name)) {
  3068.     if (CARETH)
  3069.         return 0;
  3070.     if (wizard || peek)
  3071.         msg_print("Careth Asdriag");
  3072.     else
  3073.         good_item_flag = TRUE;
  3074.     t_ptr->name2 = SN_CARETH;
  3075.     t_ptr->tohit = 6;
  3076.     t_ptr->todam = 8;
  3077.     t_ptr->flags |= (TR_SLAY_DRAGON | TR_SLAY_ANIMAL);
  3078.     t_ptr->flags2 |= (TR_SLAY_GIANT | TR_SLAY_ORC | TR_SLAY_TROLL | TR_ARTIFACT |
  3079.               TR_ATTACK_SPD);
  3080.     t_ptr->p1 = 1;
  3081.     t_ptr->cost = 25000L;
  3082.     CARETH = 1;
  3083.     return 1;
  3084.     } else if (!stricmp("& Rapier", name)) {
  3085.     if (FORASGIL)
  3086.         return 0;
  3087.     if (wizard || peek)
  3088.         msg_print("Forasgil");
  3089.     else
  3090.         good_item_flag = TRUE;
  3091.     t_ptr->name2 = SN_FORASGIL;
  3092.     t_ptr->tohit = 12;
  3093.     t_ptr->todam = 19;
  3094.     t_ptr->flags |= (TR_RES_COLD | TR_FROST_BRAND | TR_SLAY_ANIMAL);
  3095.     t_ptr->flags2 |= (TR_LIGHT | TR_RES_LT | TR_ARTIFACT);
  3096.     t_ptr->cost = 15000L;
  3097.     FORASGIL = 1;
  3098.     return 1;
  3099.     } else if (!stricmp("& Executioner's Sword", name)) {
  3100.     if (randint(2) > 1)
  3101.         return 0;
  3102.     if (CRISDURIAN)
  3103.         return 0;
  3104.     if (wizard || peek)
  3105.         msg_print("Crisdurian");
  3106.     else
  3107.         good_item_flag = TRUE;
  3108.     t_ptr->name2 = SN_CRISDURIAN;
  3109.     t_ptr->tohit = 18;
  3110.     t_ptr->todam = 19;
  3111.     t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_EVIL | TR_SLAY_UNDEAD | TR_SLAY_DRAGON);
  3112.     t_ptr->flags2 |= (TR_SLAY_GIANT | TR_SLAY_ORC | TR_SLAY_TROLL | TR_ARTIFACT);
  3113.     t_ptr->cost = 100000L;
  3114.     CRISDURIAN = 1;
  3115.     return 1;
  3116.     } else if (!stricmp("& Flail", name)) {
  3117.     if (TOTILA)
  3118.         return 0;
  3119.     if (wizard || peek)
  3120.         msg_print("Totila");
  3121.     else
  3122.         good_item_flag = TRUE;
  3123.     t_ptr->name2 = SN_TOTILA;
  3124.     t_ptr->tohit = 6;
  3125.     t_ptr->todam = 8;
  3126.     t_ptr->damage[1] = 9;
  3127.     t_ptr->flags = (TR_STEALTH | TR_RES_FIRE | TR_FLAME_TONGUE | TR_SLAY_EVIL);
  3128.     t_ptr->flags2 |= (TR_ARTIFACT | TR_ACTIVATE | TR_RES_CONF);
  3129.     t_ptr->p1 = 2;
  3130.     t_ptr->cost = 55000L;
  3131.     TOTILA = 1;
  3132.     return 1;
  3133.     } else if (!stricmp("& Short sword", name)) {
  3134.     if (GILETTAR)
  3135.         return 0;
  3136.     if (wizard || peek)
  3137.         msg_print("Gilettar");
  3138.     else
  3139.         good_item_flag = TRUE;
  3140.     t_ptr->name2 = SN_GILETTAR;
  3141.     t_ptr->tohit = 3;
  3142.     t_ptr->todam = 7;
  3143.     t_ptr->flags = (TR_REGEN | TR_SLOW_DIGEST | TR_SLAY_ANIMAL);
  3144.     t_ptr->flags2 |= (TR_ARTIFACT | TR_ATTACK_SPD);
  3145.     t_ptr->p1 = 2;
  3146.     t_ptr->cost = 15000L;
  3147.     GILETTAR = 1;
  3148.     return 1;
  3149.     } else if (!stricmp("& Katana", name)) {
  3150.     if (randint(3) > 1)
  3151.         return 0;
  3152.     if (AGLARANG)
  3153.         return 0;
  3154.     if (wizard || peek)
  3155.         msg_print("Aglarang");
  3156.     else
  3157.         good_item_flag = TRUE;
  3158.     t_ptr->name2 = SN_AGLARANG;
  3159.     t_ptr->tohit = 0;
  3160.     t_ptr->todam = 0;
  3161.     t_ptr->damage[0] = 6;
  3162.     t_ptr->damage[1] = 8;
  3163.     t_ptr->weight = 50;
  3164.     t_ptr->flags = (TR_DEX | TR_SUST_STAT);
  3165.     t_ptr->flags2 |= (TR_ARTIFACT);
  3166.     t_ptr->p1 = 5;
  3167.     t_ptr->cost = 40000L;
  3168.     AGLARANG = 1;
  3169.     return 1;
  3170.     } else if (!stricmp("& Spear", name)) {
  3171.     switch (randint(6)) {
  3172.       case 1:
  3173.         if (AEGLOS)
  3174.         return 0;
  3175.         if (wizard || peek)
  3176.         msg_print("Aeglos");
  3177.         else
  3178.         good_item_flag = TRUE;
  3179.         t_ptr->name2 = SN_AEGLOS;
  3180.         t_ptr->tohit = 15;
  3181.         t_ptr->todam = 25;
  3182.         t_ptr->damage[0] = 1;
  3183.         t_ptr->damage[1] = 20;
  3184.         t_ptr->flags = (TR_WIS | TR_FROST_BRAND |
  3185.                 TR_RES_COLD | TR_FREE_ACT | TR_SLOW_DIGEST);
  3186.         t_ptr->flags2 |= (TR_SLAY_TROLL | TR_SLAY_ORC | TR_ACTIVATE | TR_ARTIFACT |
  3187.                   TR_BLESS_BLADE);
  3188.         t_ptr->toac = 5;
  3189.         t_ptr->p1 = 4;
  3190.         t_ptr->cost = 140000L;
  3191.         AEGLOS = 1;
  3192.         return 1;
  3193.       case 2:
  3194.       case 3:
  3195.       case 4:
  3196.       case 5:
  3197.         if (NIMLOTH)
  3198.         return 0;
  3199.         if (wizard || peek)
  3200.         msg_print("Nimloth");
  3201.         else
  3202.         good_item_flag = TRUE;
  3203.         t_ptr->name2 = SN_NIMLOTH;
  3204.         t_ptr->tohit = 11;
  3205.         t_ptr->todam = 13;
  3206.         t_ptr->flags = (TR_FROST_BRAND | TR_RES_COLD | TR_SLAY_UNDEAD |
  3207.                 TR_SEE_INVIS | TR_STEALTH);
  3208.         t_ptr->flags2 |= (TR_ARTIFACT);
  3209.         t_ptr->p1 = 3;
  3210.         t_ptr->cost = 30000L;
  3211.         NIMLOTH = 1;
  3212.         return 1;
  3213.       case 6:
  3214.         if (OROME)
  3215.         return 0;
  3216.         if (wizard || peek)
  3217.         msg_print("Orome");
  3218.         else
  3219.         good_item_flag = TRUE;
  3220.         t_ptr->name2 = SN_OROME;
  3221.         t_ptr->ident |= ID_NOSHOW_TYPE;
  3222.         t_ptr->tohit = 15;
  3223.         t_ptr->todam = 15;
  3224.         t_ptr->flags = (TR_FLAME_TONGUE | TR_SEE_INVIS | TR_SEARCH | TR_INT |
  3225.                 TR_RES_FIRE | TR_FFALL | TR_INFRA);
  3226.         t_ptr->flags2 |= (TR_ACTIVATE | TR_LIGHT | TR_SLAY_GIANT | TR_RES_LT
  3227.                   | TR_ARTIFACT | TR_BLESS_BLADE);
  3228.         t_ptr->p1 = 4;
  3229.         t_ptr->cost = 60000L;
  3230.         OROME = 1;
  3231.         return 1;
  3232.     }
  3233.     } else if (!stricmp("& Dagger", name)) {
  3234.     switch (randint(11)) {
  3235.       case 1:
  3236.         if (ANGRIST)
  3237.         return 0;
  3238.         if (wizard || peek)
  3239.         msg_print("Angrist");
  3240.         else
  3241.         good_item_flag = TRUE;
  3242.         t_ptr->name2 = SN_ANGRIST;
  3243.         t_ptr->tohit = 10;
  3244.         t_ptr->todam = 15;
  3245.         t_ptr->damage[0] = 2;
  3246.         t_ptr->damage[1] = 5;
  3247.         t_ptr->flags = (TR_DEX | TR_SLAY_EVIL | TR_SUST_STAT |
  3248.                 TR_FREE_ACT);
  3249.         t_ptr->flags2 |= (TR_SLAY_TROLL | TR_SLAY_ORC | TR_RES_DARK | TR_ARTIFACT);
  3250.         t_ptr->toac = 5;
  3251.         t_ptr->p1 = 4;
  3252.         t_ptr->cost = 100000L;
  3253.         ANGRIST = 1;
  3254.         return 1;
  3255.       case 2:
  3256.       case 3:
  3257.         if (NARTHANC)
  3258.         return 0;
  3259.         if (wizard || peek)
  3260.         msg_print("Narthanc");
  3261.         else
  3262.         good_item_flag = TRUE;
  3263.         t_ptr->name2 = SN_NARTHANC;
  3264.         t_ptr->tohit = 4;
  3265.         t_ptr->todam = 6;
  3266.         t_ptr->flags = (TR_FLAME_TONGUE | TR_RES_FIRE);
  3267.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3268.         t_ptr->cost = 12000;
  3269.         NARTHANC = 1;
  3270.         return 1;
  3271.       case 4:
  3272.       case 5:
  3273.         if (NIMTHANC)
  3274.         return 0;
  3275.         if (wizard || peek)
  3276.         msg_print("Nimthanc");
  3277.         else
  3278.         good_item_flag = TRUE;
  3279.         t_ptr->name2 = SN_NIMTHANC;
  3280.         t_ptr->tohit = 4;
  3281.         t_ptr->todam = 6;
  3282.         t_ptr->flags = (TR_FROST_BRAND | TR_RES_COLD);
  3283.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3284.         t_ptr->cost = 11000L;
  3285.         NIMTHANC = 1;
  3286.         return 1;
  3287.       case 6:
  3288.       case 7:
  3289.         if (DETHANC)
  3290.         return 0;
  3291.         if (wizard || peek)
  3292.         msg_print("Dethanc");
  3293.         else
  3294.         good_item_flag = TRUE;
  3295.         t_ptr->name2 = SN_DETHANC;
  3296.         t_ptr->tohit = 4;
  3297.         t_ptr->todam = 6;
  3298.         t_ptr->flags = (TR_RES_LIGHT);
  3299.         t_ptr->flags2 |= (TR_ACTIVATE | TR_LIGHTNING | TR_ARTIFACT);
  3300.         t_ptr->cost = 13000L;
  3301.         DETHANC = 1;
  3302.         return 1;
  3303.       case 8:
  3304.       case 9:
  3305.         if (RILIA)
  3306.         return 0;
  3307.         if (wizard || peek)
  3308.         msg_print("Rilia");
  3309.         else
  3310.         good_item_flag = TRUE;
  3311.         t_ptr->name2 = SN_RILIA;
  3312.         t_ptr->tohit = 4;
  3313.         t_ptr->todam = 3;
  3314.         t_ptr->damage[0] = 2;
  3315.         t_ptr->damage[1] = 4;
  3316.         t_ptr->flags = TR_POISON;
  3317.         t_ptr->flags2 |= (TR_ACTIVATE | TR_RES_DISENCHANT | TR_ARTIFACT);
  3318.         t_ptr->cost = 15000L;
  3319.         RILIA = 1;
  3320.         return 1;
  3321.       case 10:
  3322.       case 11:
  3323.         if (BELANGIL)
  3324.         return 0;
  3325.         if (wizard || peek)
  3326.         msg_print("Belangil");
  3327.         else
  3328.         good_item_flag = TRUE;
  3329.         t_ptr->name2 = SN_BELANGIL;
  3330.         t_ptr->tohit = 6;
  3331.         t_ptr->todam = 9;
  3332.         t_ptr->damage[0] = 3;
  3333.         t_ptr->damage[1] = 2;
  3334.         t_ptr->flags = (TR_FROST_BRAND | TR_RES_COLD | TR_REGEN | TR_SLOW_DIGEST |
  3335.                 TR_DEX | TR_SEE_INVIS);
  3336.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3337.         t_ptr->p1 = 2;
  3338.         t_ptr->cost = 40000L;
  3339.         BELANGIL = 1;
  3340.         return 1;
  3341.     }
  3342.     } else if (!stricmp("& Small sword", name)) {
  3343.     if (STING)
  3344.         return 0;
  3345.     if (wizard || peek)
  3346.         msg_print("Sting");
  3347.     else
  3348.         good_item_flag = TRUE;
  3349.     t_ptr->name2 = SN_STING;
  3350.     t_ptr->tohit = 7;
  3351.     t_ptr->todam = 8;
  3352.     t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_EVIL |
  3353.              TR_SLAY_UNDEAD | TR_DEX | TR_CON | TR_STR |
  3354.              TR_FREE_ACT);
  3355.     t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_ORC | TR_LIGHT | TR_RES_LT |
  3356.               TR_ATTACK_SPD);
  3357.     t_ptr->p1 = 2;
  3358.     t_ptr->cost = 100000L;
  3359.     STING = 1;
  3360.     return 1;
  3361.     } else if (!stricmp("& Great Axe", name)) {
  3362.     switch (randint(2)) {
  3363.       case 1:
  3364.         if (randint(6) > 1)
  3365.         return 0;
  3366.         if (DURIN)
  3367.         return 0;
  3368.         if (wizard || peek)
  3369.         msg_print("Durin");
  3370.         else
  3371.         good_item_flag = TRUE;
  3372.         t_ptr->name2 = SN_DURIN;
  3373.         t_ptr->tohit = 10;
  3374.         t_ptr->todam = 20;
  3375.         t_ptr->toac = 15;
  3376.         t_ptr->flags = (TR_SLAY_X_DRAGON | TR_CON | TR_FREE_ACT |
  3377.                 TR_RES_FIRE | TR_RES_ACID);
  3378.         t_ptr->flags2 |= (TR_SLAY_DEMON | TR_SLAY_TROLL | TR_SLAY_ORC | TR_RES_DARK
  3379.                   | TR_RES_LT | TR_RES_CHAOS | TR_ARTIFACT);
  3380.         t_ptr->p1 = 3;
  3381.         t_ptr->cost = 150000L;
  3382.         DURIN = 1;
  3383.         return 1;
  3384.       case 2:
  3385.         if (randint(8) > 1)
  3386.         return 0;
  3387.         if (EONWE)
  3388.         return 0;
  3389.         if (wizard || peek)
  3390.         msg_print("Eonwe");
  3391.         else
  3392.         good_item_flag = TRUE;
  3393.         t_ptr->name2 = SN_EONWE;
  3394.         t_ptr->tohit = 15;
  3395.         t_ptr->todam = 18;
  3396.         t_ptr->toac = 8;
  3397.         t_ptr->flags = (TR_STATS | TR_SLAY_EVIL | TR_SLAY_UNDEAD | TR_FROST_BRAND |
  3398.                 TR_FREE_ACT | TR_SEE_INVIS | TR_RES_COLD);
  3399.         t_ptr->flags2 |= (TR_IM_COLD | TR_SLAY_ORC | TR_ACTIVATE | TR_ARTIFACT |
  3400.                   TR_BLESS_BLADE);
  3401.         t_ptr->p1 = 2;
  3402.         t_ptr->cost = 200000L;
  3403.         EONWE = 1;
  3404.         return 1;
  3405.     }
  3406.     } else if (!stricmp("& Battle Axe", name)) {
  3407.     switch (randint(2)) {
  3408.       case 1:
  3409.         if (BALLI)
  3410.         return 0;
  3411.         if (wizard || peek)
  3412.         msg_print("Balli Stonehand");
  3413.         else
  3414.         good_item_flag = TRUE;
  3415.         t_ptr->name2 = SN_BALLI;
  3416.         t_ptr->ident |= ID_NOSHOW_TYPE;
  3417.         t_ptr->tohit = 8;
  3418.         t_ptr->todam = 11;
  3419.         t_ptr->damage[0] = 3;
  3420.         t_ptr->damage[1] = 6;
  3421.         t_ptr->toac = 5;
  3422.         t_ptr->flags = (TR_FFALL | TR_RES_LIGHT | TR_SEE_INVIS | TR_STR | TR_CON
  3423.                 | TR_FREE_ACT | TR_RES_COLD | TR_RES_ACID
  3424.                 | TR_RES_FIRE | TR_REGEN | TR_STEALTH);
  3425.         t_ptr->flags2 |= (TR_SLAY_DEMON | TR_SLAY_TROLL | TR_SLAY_ORC | TR_RES_BLIND
  3426.                   | TR_ARTIFACT);
  3427.         t_ptr->p1 = 3;
  3428.         t_ptr->cost = 90000L;
  3429.         BALLI = 1;
  3430.         return 1;
  3431.       case 2:
  3432.         if (LOTHARANG)
  3433.         return 0;
  3434.         if (wizard || peek)
  3435.         msg_print("Lotharang");
  3436.         else
  3437.         good_item_flag = TRUE;
  3438.         t_ptr->name2 = SN_LOTHARANG;
  3439.         t_ptr->tohit = 4;
  3440.         t_ptr->todam = 3;
  3441.         t_ptr->flags = (TR_STR | TR_DEX);
  3442.         t_ptr->flags2 |= (TR_ACTIVATE | TR_SLAY_TROLL | TR_SLAY_ORC | TR_ARTIFACT);
  3443.         t_ptr->p1 = 1;
  3444.         t_ptr->cost = 21000L;
  3445.         LOTHARANG = 1;
  3446.         return 1;
  3447.     }
  3448.     } else if (!stricmp("& War Hammer", name)) {
  3449.     if (randint(10) > 1)
  3450.         return 0;
  3451.     if (AULE)
  3452.         return 0;
  3453.     if (wizard || peek)
  3454.         msg_print("Aule");
  3455.     else
  3456.         good_item_flag = TRUE;
  3457.     t_ptr->name2 = SN_AULE;
  3458.     t_ptr->damage[0] = 5;
  3459.     t_ptr->damage[1] = 5;
  3460.     t_ptr->tohit = 19;
  3461.     t_ptr->todam = 21;
  3462.     t_ptr->toac = 5;
  3463.     t_ptr->flags = (TR_SLAY_X_DRAGON | TR_SLAY_EVIL | TR_SLAY_UNDEAD |
  3464.             TR_RES_FIRE | TR_RES_ACID | TR_RES_COLD | TR_RES_LIGHT |
  3465.             TR_FREE_ACT | TR_SEE_INVIS | TR_WIS);
  3466.     t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_DEMON | TR_LIGHTNING | TR_RES_NEXUS);
  3467.     t_ptr->p1 = 4;
  3468.     t_ptr->cost = 250000L;
  3469.     AULE = 1;
  3470.     return 1;
  3471.     } else if (!stricmp("& Beaked Axe", name)) {
  3472.     if (randint(2) > 1)
  3473.         return 0;
  3474.     if (THEODEN)
  3475.         return 0;
  3476.     if (wizard || peek)
  3477.         msg_print("Theoden");
  3478.     else
  3479.         good_item_flag = TRUE;
  3480.     t_ptr->name2 = SN_THEODEN;
  3481.     t_ptr->tohit = 8;
  3482.     t_ptr->todam = 10;
  3483.     t_ptr->flags = (TR_WIS | TR_CON | TR_SEARCH | TR_SLOW_DIGEST | TR_SLAY_DRAGON);
  3484.     t_ptr->flags2 |= (TR_TELEPATHY | TR_ACTIVATE | TR_ARTIFACT);
  3485.     t_ptr->ident |= ID_NOSHOW_TYPE;
  3486.     t_ptr->p1 = 3;
  3487.     t_ptr->cost = 40000L;
  3488.     THEODEN = 1;
  3489.     return 1;
  3490.     } else if (!stricmp("& Two-Handed Great Flail", name)) {
  3491.     if (randint(5) > 1)
  3492.         return 0;
  3493.     if (THUNDERFIST)
  3494.         return 0;
  3495.     if (wizard || peek)
  3496.         msg_print("Thunderfist");
  3497.     else
  3498.         good_item_flag = TRUE;
  3499.     t_ptr->name2 = SN_THUNDERFIST;
  3500.     t_ptr->tohit = 5;
  3501.     t_ptr->todam = 18;
  3502.     t_ptr->flags = (TR_SLAY_ANIMAL | TR_STR | TR_FLAME_TONGUE |
  3503.             TR_RES_FIRE | TR_RES_LIGHT);
  3504.     t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_TROLL | TR_SLAY_ORC
  3505.               | TR_LIGHTNING | TR_RES_DARK);
  3506.     t_ptr->p1 = 4;
  3507.     t_ptr->cost = 160000L;
  3508.     THUNDERFIST = 1;
  3509.     return 1;
  3510.     } else if (!stricmp("& Morningstar", name)) {
  3511.     switch (randint(2)) {
  3512.       case 1:
  3513.         if (randint(2) > 1)
  3514.         return 0;
  3515.         if (BLOODSPIKE)
  3516.         return 0;
  3517.         if (wizard || peek)
  3518.         msg_print("Bloodspike");
  3519.         else
  3520.         good_item_flag = TRUE;
  3521.         t_ptr->name2 = SN_BLOODSPIKE;
  3522.         t_ptr->tohit = 8;
  3523.         t_ptr->todam = 22;
  3524.         t_ptr->flags = (TR_SLAY_ANIMAL | TR_STR | TR_SEE_INVIS);
  3525.         t_ptr->flags2 |= (TR_ARTIFACT | TR_SLAY_TROLL | TR_SLAY_ORC | TR_RES_NEXUS);
  3526.         t_ptr->p1 = 4;
  3527.         t_ptr->cost = 30000L;
  3528.         BLOODSPIKE = 1;
  3529.         return 1;
  3530.       case 2:
  3531.         if (FIRESTAR)
  3532.         return 0;
  3533.         if (wizard || peek)
  3534.         msg_print("Firestar");
  3535.         else
  3536.         good_item_flag = TRUE;
  3537.         t_ptr->name2 = SN_FIRESTAR;
  3538.         t_ptr->tohit = 5;
  3539.         t_ptr->todam = 7;
  3540.         t_ptr->flags = (TR_FLAME_TONGUE | TR_RES_FIRE);
  3541.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3542.         t_ptr->toac = 2;
  3543.         t_ptr->cost = 35000L;
  3544.         FIRESTAR = 1;
  3545.         return 1;
  3546.     }
  3547.     } else if (!stricmp("& Blade of Chaos", name)) {
  3548.     if (DOOMCALLER)
  3549.         return 0;
  3550.     if (randint(3) > 1)
  3551.         return 0;
  3552.     if (wizard || peek)
  3553.         msg_print("Doomcaller");
  3554.     else
  3555.         good_item_flag = TRUE;
  3556.     t_ptr->name2 = SN_DOOMCALLER;
  3557.     t_ptr->tohit = 18;
  3558.     t_ptr->todam = 28;
  3559.     t_ptr->flags = (TR_CON | TR_SLAY_ANIMAL | TR_SLAY_X_DRAGON |
  3560.         TR_FROST_BRAND | TR_SLAY_EVIL | TR_FREE_ACT | TR_SEE_INVIS |
  3561.             TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT | TR_RES_ACID |
  3562.             TR_AGGRAVATE);
  3563.     t_ptr->flags2 |= (TR_SLAY_TROLL | TR_SLAY_ORC | TR_TELEPATHY | TR_ARTIFACT);
  3564.     t_ptr->p1 = -5;
  3565.     t_ptr->cost = 200000L;
  3566.     DOOMCALLER = 1;
  3567.     return 1;
  3568.     } else if (!stricmp("& Quarterstaff", name)) {
  3569.     switch (randint(7)) {
  3570.       case 1:
  3571.       case 2:
  3572.       case 3:
  3573.         if (NAR)
  3574.         return 0;
  3575.         if (wizard || peek)
  3576.         msg_print("Nar-i-vagil");
  3577.         else
  3578.         good_item_flag = TRUE;
  3579.         t_ptr->name2 = SN_NAR;
  3580.         t_ptr->tohit = 10;
  3581.         t_ptr->todam = 20;
  3582.         t_ptr->flags = (TR_INT | TR_SLAY_ANIMAL | TR_FLAME_TONGUE | TR_RES_FIRE);
  3583.         t_ptr->flags2 |= (TR_ARTIFACT);
  3584.         t_ptr->p1 = 3;
  3585.         t_ptr->cost = 70000L;
  3586.         NAR = 1;
  3587.         return 1;
  3588.       case 4:
  3589.       case 5:
  3590.       case 6:
  3591.         if (ERIRIL)
  3592.         return 0;
  3593.         if (wizard || peek)
  3594.         msg_print("Eriril");
  3595.         else
  3596.         good_item_flag = TRUE;
  3597.         t_ptr->name2 = SN_ERIRIL;
  3598.         t_ptr->tohit = 3;
  3599.         t_ptr->todam = 5;
  3600.         t_ptr->flags = (TR_SLAY_EVIL | TR_SEE_INVIS | TR_INT | TR_WIS);
  3601.         t_ptr->flags2 |= (TR_LIGHT | TR_ACTIVATE | TR_RES_LT | TR_ARTIFACT);
  3602.         t_ptr->p1 = 4;
  3603.         t_ptr->cost = 20000L;
  3604.         ERIRIL = 1;
  3605.         return 1;
  3606.       case 7:
  3607.         if (OLORIN)
  3608.         return 0;
  3609.         if (randint(2) > 1)
  3610.         return 0;
  3611.         if (wizard || peek)
  3612.         msg_print("Olorin");
  3613.         else
  3614.         good_item_flag = TRUE;
  3615.         t_ptr->name2 = SN_OLORIN;
  3616.         t_ptr->tohit = 10;
  3617.         t_ptr->todam = 13;
  3618.         t_ptr->damage[0] = 2;
  3619.         t_ptr->damage[1] = 10;
  3620.         t_ptr->flags = (TR_SLAY_EVIL | TR_SEE_INVIS | TR_WIS | TR_INT | TR_CHR
  3621.                 | TR_FLAME_TONGUE | TR_RES_FIRE);
  3622.         t_ptr->flags2 |= (TR_ARTIFACT | TR_HOLD_LIFE | TR_SLAY_ORC | TR_SLAY_TROLL
  3623.                   | TR_ACTIVATE | TR_RES_NETHER);
  3624.         t_ptr->p1 = 4;
  3625.         t_ptr->cost = 130000L;
  3626.         OLORIN = 1;
  3627.         return 1;
  3628.     }
  3629.     }
  3630.     return 0;
  3631. }
  3632.  
  3633. int 
  3634. unique_armour(t_ptr)
  3635. inven_type *t_ptr;
  3636. {
  3637.     const char *name;
  3638.  
  3639.     if (be_nasty)
  3640.     return 0;
  3641.     name = object_list[t_ptr->index].name;
  3642.     if (!strncmp("Adamantite", name, 10)) {
  3643.     if (SOULKEEPER)
  3644.         return 0;
  3645.     if (randint(3) > 1)
  3646.         return 0;
  3647.     if (wizard || peek)
  3648.         msg_print("Soulkeeper");
  3649.     else
  3650.         good_item_flag = TRUE;
  3651.     t_ptr->flags |= (TR_RES_ACID | TR_RES_COLD);
  3652.     t_ptr->flags2 |= (TR_HOLD_LIFE | TR_ACTIVATE | TR_RES_CHAOS | TR_RES_DARK |
  3653.               TR_RES_NEXUS | TR_RES_NETHER | TR_ARTIFACT);
  3654.     t_ptr->name2 = SN_SOULKEEPER;
  3655.     t_ptr->toac = 20;
  3656.     t_ptr->cost = 300000L;
  3657.     SOULKEEPER = 1;
  3658.     return 1;
  3659.     }
  3660.      /* etc..... */ 
  3661.     else if (!strncmp("Multi-Hued", name, 10)) {
  3662.     if (RAZORBACK)
  3663.         return 0;
  3664.     if (randint(3) > 1)
  3665.         return 0;
  3666.     if (wizard || peek)
  3667.         msg_print("Razorback");
  3668.     else
  3669.         good_item_flag = TRUE;
  3670.     t_ptr->flags |= (TR_RES_FIRE | TR_RES_COLD | TR_RES_ACID | TR_POISON |
  3671.              TR_RES_LIGHT | TR_FREE_ACT | TR_SEE_INVIS | TR_INT |
  3672.              TR_WIS | TR_STEALTH | TR_AGGRAVATE);
  3673.     t_ptr->flags2 |= (TR_ACTIVATE | TR_LIGHT | TR_IM_LIGHT | TR_RES_LT |
  3674.               TR_ARTIFACT);
  3675.     t_ptr->ident |= ID_NOSHOW_TYPE;
  3676.     t_ptr->toac = 25;
  3677.     t_ptr->p1 = -2;
  3678.     t_ptr->weight = 400;
  3679.     t_ptr->ac = 30;
  3680.     t_ptr->tohit = -3;
  3681.     t_ptr->cost = 400000L;
  3682.     t_ptr->name2 = SN_RAZORBACK;
  3683.     RAZORBACK = 1;
  3684.     return 1;
  3685.     } else if (!strncmp("Power Drag", name, 10)) {
  3686.     if (BLADETURNER)
  3687.         return 0;
  3688.     if (wizard || peek)
  3689.         msg_print("Bladeturner");
  3690.     else
  3691.         good_item_flag = TRUE;
  3692.     t_ptr->flags |= (TR_RES_FIRE | TR_RES_COLD | TR_RES_ACID | TR_POISON |
  3693.              TR_RES_LIGHT | TR_DEX | TR_SEARCH | TR_REGEN);
  3694.     t_ptr->flags2 |= (TR_HOLD_LIFE | TR_RES_CONF | TR_RES_SOUND | TR_RES_LT
  3695.           | TR_RES_DARK | TR_RES_CHAOS | TR_RES_DISENCHANT | TR_ARTIFACT
  3696.            | TR_RES_SHARDS | TR_RES_BLIND | TR_RES_NEXUS | TR_RES_NETHER
  3697.               | TR_ACTIVATE);
  3698.     t_ptr->ident |= ID_NOSHOW_TYPE;
  3699.     t_ptr->toac = 35;
  3700.     t_ptr->p1 = -3;
  3701.     t_ptr->ac = 50;
  3702.     t_ptr->tohit = -4;
  3703.     t_ptr->weight = 500;
  3704.     t_ptr->cost = 500000L;
  3705.     t_ptr->name2 = SN_BLADETURNER;
  3706.     BLADETURNER = 1;
  3707.     return 1;
  3708.     } else if (!stricmp("& Pair of Hard Leather Boots", name)) {
  3709.     if (FEANOR)
  3710.         return 0;
  3711.     if (randint(5) > 1)
  3712.         return 0;
  3713.     if (wizard || peek)
  3714.         msg_print("Feanor");
  3715.     else
  3716.         good_item_flag = TRUE;
  3717.     t_ptr->flags |= (TR_RES_ACID | TR_SPEED | TR_STEALTH);
  3718.     t_ptr->flags2 |= (TR_ACTIVATE | TR_RES_NEXUS | TR_ARTIFACT);
  3719.     t_ptr->name2 = SN_FEANOR;
  3720.     t_ptr->p1 = 1;
  3721.     t_ptr->toac = 20;
  3722.     t_ptr->cost = 130000L;
  3723.     FEANOR = 1;
  3724.     return 1;
  3725.     } else if (!stricmp("& Pair of Soft Leather Boots", name)) {
  3726.     if (DAL)
  3727.         return 0;
  3728.     if (wizard || peek)
  3729.         msg_print("Dal-i-thalion");
  3730.     else
  3731.         good_item_flag = TRUE;
  3732.     t_ptr->flags |= (TR_FREE_ACT | TR_DEX | TR_SUST_STAT | TR_RES_ACID);
  3733.     t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT | TR_RES_NETHER | TR_RES_CHAOS);
  3734.     t_ptr->name2 = SN_DAL;
  3735.     t_ptr->p1 = 5;
  3736.     t_ptr->toac = 15;
  3737.     t_ptr->cost = 40000L;
  3738.     DAL = 1;
  3739.     return 1;
  3740.     } else if (!stricmp("& Small Metal Shield", name)) {
  3741.     if (THORIN)
  3742.         return 0;
  3743.     if (randint(2) > 1)
  3744.         return 0;
  3745.     if (wizard || peek)
  3746.         msg_print("Thorin");
  3747.     else
  3748.         good_item_flag = TRUE;
  3749.     t_ptr->flags |= (TR_CON | TR_FREE_ACT | TR_STR |
  3750.              TR_RES_ACID | TR_SEARCH);
  3751.     t_ptr->flags2 |= (TR_RES_SOUND | TR_RES_CHAOS | TR_ARTIFACT | TR_IM_ACID);
  3752.     t_ptr->name2 = SN_THORIN;
  3753.     t_ptr->ident |= ID_NOSHOW_TYPE;
  3754.     t_ptr->tohit = 0;
  3755.     t_ptr->p1 = 4;
  3756.     t_ptr->toac = 25;
  3757.     t_ptr->cost = 60000L;
  3758.     THORIN = 1;
  3759.     return 1;
  3760.     } else if (!stricmp("Full Plate Armour", name)) {
  3761.     if (ISILDUR)
  3762.         return 0;
  3763.     if (wizard || peek)
  3764.         msg_print("Isildur");
  3765.     else
  3766.         good_item_flag = TRUE;
  3767.     t_ptr->weight = 300;
  3768.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT);
  3769.     t_ptr->flags2 |= (TR_RES_SOUND | TR_ARTIFACT | TR_RES_NEXUS);
  3770.     t_ptr->name2 = SN_ISILDUR;
  3771.     t_ptr->tohit = 0;
  3772.     t_ptr->toac = 25;
  3773.     t_ptr->cost = 40000L;
  3774.     ISILDUR = 1;
  3775.     return 1;
  3776.     } else if (!stricmp("Metal Brigandine Armour", name)) {
  3777.     if (ROHAN)
  3778.         return 0;
  3779.     if (wizard || peek)
  3780.         msg_print("Rohirrim");
  3781.     else
  3782.         good_item_flag = TRUE;
  3783.     t_ptr->weight = 200;
  3784.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT |
  3785.              TR_STR | TR_DEX);
  3786.     t_ptr->flags2 |= (TR_RES_SOUND | TR_RES_CONF | TR_ARTIFACT);
  3787.     t_ptr->name2 = SN_ROHAN;
  3788.     t_ptr->tohit = 0;
  3789.     t_ptr->p1 = 2;
  3790.     t_ptr->toac = 15;
  3791.     t_ptr->cost = 30000L;
  3792.     ROHAN = 1;
  3793.     return 1;
  3794.     } else if (!stricmp("& Large Metal Shield", name)) {
  3795.     if (ANARION)
  3796.         return 0;
  3797.     if (randint(3) > 1)
  3798.         return 0;
  3799.     else
  3800.         good_item_flag = TRUE;
  3801.     if (wizard || peek)
  3802.         msg_print("Anarion");
  3803.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT |
  3804.              TR_SUST_STAT);
  3805.     t_ptr->flags2 |= (TR_ARTIFACT);
  3806.     t_ptr->name2 = SN_ANARION;
  3807.     t_ptr->p1 = 10;
  3808.     t_ptr->ident |= ID_NOSHOW_P1;
  3809.     t_ptr->tohit = 0;
  3810.     t_ptr->toac = 20;
  3811.     t_ptr->cost = 160000L;
  3812.     ANARION = 1;
  3813.     return 1;
  3814.     } else if (!stricmp("& Set of Cesti", name)) {
  3815.     if (FINGOLFIN)
  3816.         return 0;
  3817.     if (randint(3) > 1)
  3818.         return 0;
  3819.     if (wizard || peek)
  3820.         msg_print("Fingolfin");
  3821.     else
  3822.         good_item_flag = TRUE;
  3823.     t_ptr->flags |= (TR_RES_ACID | TR_DEX | TR_FREE_ACT);
  3824.     t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3825.     t_ptr->name2 = SN_FINGOLFIN;
  3826.     t_ptr->ident |= ID_SHOW_HITDAM;
  3827.     t_ptr->p1 = 4;
  3828.     t_ptr->tohit = 10;
  3829.     t_ptr->todam = 10;
  3830.     t_ptr->toac = 20;
  3831.     t_ptr->cost = 110000L;
  3832.     FINGOLFIN = 1;
  3833.     return 1;
  3834.     } else if (!stricmp("& Set of Leather Gloves", name)) {
  3835.     if (randint(3) == 1) {
  3836.         if (CAMBELEG)
  3837.         return 0;
  3838.         if (wizard || peek)
  3839.         msg_print("Cambeleg");
  3840.         else
  3841.         good_item_flag = TRUE;
  3842.         t_ptr->flags |= (TR_STR | TR_CON | TR_FREE_ACT);
  3843.         t_ptr->flags2 |= (TR_ARTIFACT);
  3844.         t_ptr->name2 = SN_CAMBELEG;
  3845.         t_ptr->ident |= ID_SHOW_HITDAM;
  3846.         t_ptr->p1 = 2;
  3847.         t_ptr->tohit = 8;
  3848.         t_ptr->todam = 8;
  3849.         t_ptr->toac = 15;
  3850.         t_ptr->cost = 36000L;
  3851.         CAMBELEG = 1;
  3852.         return 1;
  3853.     } else {
  3854.         if (CAMMITHRIM)
  3855.         return 0;
  3856.         if (wizard || peek)
  3857.         msg_print("Cammithrim");
  3858.         else
  3859.         good_item_flag = TRUE;
  3860.         t_ptr->flags |= (TR_SUST_STAT | TR_FREE_ACT);
  3861.         t_ptr->flags2 |= (TR_ACTIVATE | TR_LIGHT | TR_RES_LT | TR_ARTIFACT);
  3862.         t_ptr->name2 = SN_CAMMITHRIM;
  3863.         t_ptr->ident |= ID_NOSHOW_P1;
  3864.         t_ptr->p1 = 5;
  3865.         t_ptr->toac = 10;
  3866.         t_ptr->cost = 30000L;
  3867.         CAMMITHRIM = 1;
  3868.         return 1;
  3869.     }
  3870.     } else if (!stricmp("& Set of Gauntlets", name)) {
  3871.     switch (randint(6)) {
  3872.       case 1:
  3873.         if (PAURHACH)
  3874.         return 0;
  3875.         if (wizard || peek)
  3876.         msg_print("Paurhach");
  3877.         else
  3878.         good_item_flag = TRUE;
  3879.         t_ptr->flags |= TR_RES_FIRE;
  3880.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3881.         t_ptr->name2 = SN_PAURHACH;
  3882.         t_ptr->toac = 15;
  3883.         t_ptr->cost = 15000L;
  3884.         PAURHACH = 1;
  3885.         return 1;
  3886.       case 2:
  3887.         if (PAURNIMMEN)
  3888.         return 0;
  3889.         if (wizard || peek)
  3890.         msg_print("Paurnimmen");
  3891.         else
  3892.         good_item_flag = TRUE;
  3893.         t_ptr->flags |= TR_RES_COLD;
  3894.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3895.         t_ptr->name2 = SN_PAURNIMMEN;
  3896.         t_ptr->toac = 15;
  3897.         t_ptr->cost = 13000L;
  3898.         PAURNIMMEN = 1;
  3899.         return 1;
  3900.       case 3:
  3901.         if (PAURAEGEN)
  3902.         return 0;
  3903.         if (wizard || peek)
  3904.         msg_print("Pauraegen");
  3905.         else
  3906.         good_item_flag = TRUE;
  3907.         t_ptr->flags |= TR_RES_LIGHT;
  3908.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3909.         t_ptr->name2 = SN_PAURAEGEN;
  3910.         t_ptr->toac = 15;
  3911.         t_ptr->cost = 11000L;
  3912.         PAURAEGEN = 1;
  3913.         return 1;
  3914.       case 4:
  3915.         if (PAURNEN)
  3916.         return 0;
  3917.         if (wizard || peek)
  3918.         msg_print("Paurnen");
  3919.         else
  3920.         good_item_flag = TRUE;
  3921.         t_ptr->flags |= TR_RES_ACID;
  3922.         t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3923.         t_ptr->name2 = SN_PAURNEN;
  3924.         t_ptr->toac = 15;
  3925.         t_ptr->cost = 12000L;
  3926.         PAURNEN = 1;
  3927.         return 1;
  3928.       default:
  3929.         if (CAMLOST)
  3930.         return 0;
  3931.         if (wizard || peek)
  3932.         msg_print("Camlost");
  3933.         else
  3934.         good_item_flag = TRUE;
  3935.         t_ptr->flags |= (TR_STR | TR_DEX | TR_AGGRAVATE | TR_CURSED);
  3936.         t_ptr->flags2 |= (TR_ARTIFACT);
  3937.         t_ptr->name2 = SN_CAMLOST;
  3938.         t_ptr->toac = 0;
  3939.         t_ptr->p1 = -5;
  3940.         t_ptr->tohit = -11;
  3941.         t_ptr->todam = -12;
  3942.         t_ptr->ident |= (ID_SHOW_HITDAM/* | ID_SHOW_P1*/);
  3943.         t_ptr->cost = 0L;
  3944.         CAMLOST = 1;
  3945.         return 1;
  3946.     }
  3947.     } else if (!stricmp("Mithril Chain Mail", name)) {
  3948.     if (BELEGENNON)
  3949.         return 0;
  3950.     if (wizard || peek)
  3951.         msg_print("Belegennon");
  3952.     else
  3953.         good_item_flag = TRUE;
  3954.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD |
  3955.              TR_RES_LIGHT | TR_STEALTH);
  3956.     t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  3957.     t_ptr->name2 = SN_BELEGENNON;
  3958.     t_ptr->p1 = 4;
  3959.     t_ptr->toac = 20;
  3960.     t_ptr->cost = 105000L;
  3961.     BELEGENNON = 1;
  3962.     return 1;
  3963.     } else if (!stricmp("Mithril Plate Mail", name)) {
  3964.     if (CELEBORN)
  3965.         return 0;
  3966.     if (wizard || peek)
  3967.         msg_print("Celeborn");
  3968.     else
  3969.         good_item_flag = TRUE;
  3970.     t_ptr->weight = 250;
  3971.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT |
  3972.              TR_STR | TR_CHR);
  3973.     t_ptr->flags2 |= (TR_ACTIVATE | TR_RES_DISENCHANT | TR_RES_DARK | TR_ARTIFACT);
  3974.     t_ptr->name2 = SN_CELEBORN;
  3975.     t_ptr->p1 = 4;
  3976.     t_ptr->toac = 25;
  3977.     t_ptr->cost = 150000L;
  3978.     CELEBORN = 1;
  3979.     return 1;
  3980.     } else if (!stricmp("Augmented Chain Mail", name)) {
  3981.     if (randint(3) > 1)
  3982.         return 0;
  3983.     if (CASPANION)
  3984.         return 0;
  3985.     if (wizard || peek)
  3986.         msg_print("Caspanion");
  3987.     else
  3988.         good_item_flag = TRUE;
  3989.     t_ptr->flags |= (TR_RES_ACID | TR_POISON | TR_CON | TR_WIS | TR_INT);
  3990.     t_ptr->flags2 |= (TR_RES_CONF | TR_ACTIVATE | TR_ARTIFACT);
  3991.     t_ptr->name2 = SN_CASPANION;
  3992.     t_ptr->p1 = 3;
  3993.     t_ptr->toac = 20;
  3994.     t_ptr->cost = 40000L;
  3995.     CASPANION = 1;
  3996.     return 1;
  3997.     } else if (!stricmp("Soft Leather Armour", name)) {
  3998.     if (HITHLOMIR)
  3999.         return 0;
  4000.     if (wizard || peek)
  4001.         msg_print("Hithlomir");
  4002.     else
  4003.         good_item_flag = TRUE;
  4004.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT |
  4005.              TR_STEALTH);
  4006.     t_ptr->flags2 |= (TR_ARTIFACT | TR_RES_DARK);
  4007.     t_ptr->name2 = SN_HITHLOMIR;
  4008.     t_ptr->p1 = 4;
  4009.     t_ptr->toac = 20;
  4010.     t_ptr->cost = 45000L;
  4011.     HITHLOMIR = 1;
  4012.     return 1;
  4013.     } else if (!stricmp("Leather Scale Mail", name)) {
  4014.     if (THALKETTOTH)
  4015.         return 0;
  4016.     if (wizard || peek)
  4017.         msg_print("Thalkettoth");
  4018.     else
  4019.         good_item_flag = TRUE;
  4020.     t_ptr->weight = 60;
  4021.     t_ptr->flags |= (TR_RES_ACID | TR_DEX);
  4022.     t_ptr->flags2 |= (TR_ARTIFACT | TR_RES_SHARDS);
  4023.     t_ptr->name2 = SN_THALKETTOTH;
  4024.     t_ptr->toac = 25;
  4025.     t_ptr->p1 = 3;
  4026.     t_ptr->cost = 25000L;
  4027.     THALKETTOTH = 1;
  4028.     return 1;
  4029.     } else if (!stricmp("Chain Mail", name)) {
  4030.     if (ARVEDUI)
  4031.         return 0;
  4032.     if (wizard || peek)
  4033.         msg_print("Arvedui");
  4034.     else
  4035.         good_item_flag = TRUE;
  4036.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT |
  4037.              TR_STR | TR_CHR);
  4038.     t_ptr->flags2 |= (TR_ARTIFACT | TR_RES_NEXUS | TR_RES_SHARDS);
  4039.     t_ptr->name2 = SN_ARVEDUI;
  4040.     t_ptr->p1 = 2;
  4041.     t_ptr->toac = 15;
  4042.     t_ptr->cost = 32000L;
  4043.     ARVEDUI = 1;
  4044.     return 1;
  4045.     } else if (!stricmp("& Hard Leather Cap", name)) {
  4046.     if (THRANDUIL)
  4047.         return 0;
  4048.     if (wizard || peek)
  4049.         msg_print("Thranduil");
  4050.     else
  4051.         good_item_flag = TRUE;
  4052.     t_ptr->flags |= (TR_RES_ACID | TR_INT | TR_WIS);
  4053.     t_ptr->flags2 |= (TR_TELEPATHY | TR_RES_BLIND | TR_ARTIFACT);
  4054.     t_ptr->name2 = SN_THRANDUIL;
  4055.     t_ptr->p1 = 2;
  4056.     t_ptr->toac = 10;
  4057.     t_ptr->cost = 50000L;
  4058.     THRANDUIL = 1;
  4059.     return 1;
  4060.     } else if (!stricmp("& Metal Cap", name)) {
  4061.     if (THENGEL)
  4062.         return 0;
  4063.     if (wizard || peek)
  4064.         msg_print("Thengel");
  4065.     else
  4066.         good_item_flag = TRUE;
  4067.     t_ptr->flags |= (TR_RES_ACID | TR_WIS | TR_CHR);
  4068.     t_ptr->flags2 |= (TR_ARTIFACT);
  4069.     t_ptr->name2 = SN_THENGEL;
  4070.     t_ptr->p1 = 3;
  4071.     t_ptr->toac = 12;
  4072.     t_ptr->cost = 22000L;
  4073.     THENGEL = 1;
  4074.     return 1;
  4075.     } else if (!stricmp("& Steel Helm", name)) {
  4076.     if (HAMMERHAND)
  4077.         return 0;
  4078.     if (wizard || peek)
  4079.         msg_print("Hammerhand");
  4080.     else
  4081.         good_item_flag = TRUE;
  4082.     t_ptr->flags |= (TR_STR | TR_CON | TR_DEX | TR_RES_ACID);
  4083.     t_ptr->flags2 |= (TR_ARTIFACT | TR_RES_NEXUS);
  4084.     t_ptr->name2 = SN_HAMMERHAND;
  4085.     t_ptr->p1 = 3;
  4086.     t_ptr->toac = 20;
  4087.     t_ptr->cost = 45000L;
  4088.     HAMMERHAND = 1;
  4089.     return 1;
  4090.     } else if (!stricmp("& Large Leather Shield", name)) {
  4091.     if (CELEGORM)
  4092.         return 0;
  4093.     if (wizard || peek)
  4094.         msg_print("Celegorm");
  4095.     else
  4096.         good_item_flag = TRUE;
  4097.     t_ptr->weight = 60;
  4098.     t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT);
  4099.     t_ptr->flags2 |= (TR_RES_LT | TR_RES_DARK | TR_ARTIFACT);
  4100.     t_ptr->name2 = SN_CELEGORM;
  4101.     t_ptr->toac = 20;
  4102.     t_ptr->cost = 12000L;
  4103.     CELEGORM = 1;
  4104.     return 1;
  4105.     } else if (!stricmp("& Pair of Metal Shod Boots", name)) {
  4106.     if (THROR)
  4107.         return 0;
  4108.     if (wizard || peek)
  4109.         msg_print("Thror");
  4110.     else
  4111.         good_item_flag = TRUE;
  4112.     t_ptr->flags |= (TR_CON | TR_STR | TR_RES_ACID);
  4113.     t_ptr->flags2 |= (TR_ARTIFACT);
  4114.     t_ptr->name2 = SN_THROR;
  4115.     t_ptr->p1 = 3;
  4116.     t_ptr->toac = 20;
  4117.     t_ptr->cost = 12000L;
  4118.     THROR = 1;
  4119.     return 1;
  4120.     } else if (!stricmp("& Iron Helm", name)) {
  4121.     if (randint(6) == 1) {
  4122.         if (DOR_LOMIN)
  4123.         return 0;
  4124.         if (wizard || peek)
  4125.         msg_print("Dor-Lomin");
  4126.         else
  4127.         good_item_flag = TRUE;
  4128.         t_ptr->flags |= (TR_RES_ACID | TR_RES_FIRE | TR_RES_COLD | TR_RES_LIGHT |
  4129.                  TR_CON | TR_DEX | TR_STR | TR_SEE_INVIS);
  4130.         t_ptr->flags2 |= (TR_TELEPATHY | TR_LIGHT | TR_RES_LT | TR_RES_BLIND
  4131.                   | TR_ARTIFACT);
  4132.         t_ptr->name2 = SN_DOR_LOMIN;
  4133.         t_ptr->p1 = 4;
  4134.         t_ptr->toac = 20;
  4135.         t_ptr->cost = 300000L;
  4136.         DOR_LOMIN = 1;
  4137.         return 1;
  4138.     } else if (randint(2) == 1) {
  4139.         if (HOLHENNETH)
  4140.         return 0;
  4141.         if (wizard || peek)
  4142.         msg_print("Holhenneth");
  4143.         else
  4144.         good_item_flag = TRUE;
  4145.         t_ptr->flags |= (TR_INT | TR_WIS | TR_SEE_INVIS | TR_SEARCH | TR_RES_ACID);
  4146.         t_ptr->flags2 |= (TR_ACTIVATE | TR_RES_BLIND | TR_ARTIFACT);
  4147.         t_ptr->name2 = SN_HOLHENNETH;
  4148.         t_ptr->ident |= ID_NOSHOW_TYPE;
  4149.         t_ptr->p1 = 2;
  4150.         t_ptr->toac = 10;
  4151.         t_ptr->cost = 100000L;
  4152.         HOLHENNETH = 1;
  4153.         return 1;
  4154.     } else {
  4155.         if (GORLIM)
  4156.         return 0;
  4157.         if (wizard || peek)
  4158.         msg_print("Gorlim");
  4159.         else
  4160.         good_item_flag = TRUE;
  4161.         t_ptr->flags |= (TR_INT | TR_WIS | TR_SEE_INVIS | TR_SEARCH | TR_CURSED
  4162.                  | TR_AGGRAVATE);
  4163.         t_ptr->flags2 |= (TR_ARTIFACT);
  4164.         t_ptr->name2 = SN_GORLIM;
  4165.         t_ptr->ident |= ID_NOSHOW_TYPE;
  4166.         t_ptr->p1 = -125;
  4167.         t_ptr->toac = 10;
  4168.         t_ptr->cost = 0L;
  4169.         GORLIM = 1;
  4170.         return 1;
  4171.     }
  4172.     } else if (!stricmp("& Golden Crown", name)) {
  4173.     if (randint(3) > 1)
  4174.         return 0;
  4175.     if (GONDOR)
  4176.         return 0;
  4177.     if (wizard || peek)
  4178.         msg_print("Gondor");
  4179.     else
  4180.         good_item_flag = TRUE;
  4181.     t_ptr->name2 = SN_GONDOR;
  4182.     t_ptr->flags = (TR_STR | TR_CON | TR_WIS | TR_SEE_INVIS | TR_REGEN
  4183.             | TR_RES_ACID | TR_RES_FIRE);
  4184.     t_ptr->flags2 = (TR_ACTIVATE | TR_LIGHT | TR_RES_LT | TR_RES_BLIND |
  4185.              TR_ARTIFACT);
  4186.     t_ptr->p1 = 3;
  4187.     t_ptr->toac = 15;
  4188.     t_ptr->cost = 100000L;
  4189.     GONDOR = 1;
  4190.     return 1;
  4191.     } else if (!stricmp("& Iron Crown", name)) {
  4192.     if (BERUTHIEL)
  4193.         return 0;
  4194.     if (wizard || peek)
  4195.         msg_print("Beruthiel");
  4196.     else
  4197.         good_item_flag = TRUE;
  4198.     t_ptr->flags |= (TR_STR | TR_DEX | TR_CON |
  4199.               TR_RES_ACID | TR_SEE_INVIS | TR_FREE_ACT | TR_CURSED);
  4200.     t_ptr->flags2 |= (TR_TELEPATHY | TR_ARTIFACT);
  4201.     t_ptr->name2 = SN_BERUTHIEL;
  4202.     t_ptr->p1 = -125;
  4203.     t_ptr->toac = 20;
  4204.     t_ptr->cost = 10000L;
  4205.     BERUTHIEL = 1;
  4206.     return 1;
  4207.     }
  4208.     return 0;
  4209. }
  4210.  
  4211. void 
  4212. give_1_hi_resist(t)           /* JLS: gives one of the "new" resistances to */
  4213. register inven_type *t;
  4214. {
  4215.     switch (randint(10)) {
  4216.       case 1:
  4217.     t->flags2 |= TR_RES_CONF;
  4218.     break;
  4219.       case 2:
  4220.     t->flags2 |= TR_RES_SOUND;
  4221.     break;
  4222.       case 3:
  4223.     t->flags2 |= TR_RES_LT;
  4224.     break;
  4225.       case 4:
  4226.     t->flags2 |= TR_RES_DARK;
  4227.     break;
  4228.       case 5:
  4229.     t->flags2 |= TR_RES_CHAOS;
  4230.     break;
  4231.       case 6:
  4232.     t->flags2 |= TR_RES_DISENCHANT;
  4233.     break;
  4234.       case 7:
  4235.     t->flags2 |= TR_RES_SHARDS;
  4236.     break;
  4237.       case 8:
  4238.     t->flags2 |= TR_RES_NEXUS;
  4239.     break;
  4240.       case 9:
  4241.     t->flags2 |= TR_RES_BLIND;
  4242.     break;
  4243.       case 10:
  4244.     t->flags2 |= TR_RES_NETHER;
  4245.     break;
  4246.     }
  4247. }
  4248.  
  4249. /* Chance of treasure having magic abilities        -RAK-     */
  4250. /* Chance increases with each dungeon level             */
  4251. void 
  4252. magic_treasure(x, level, good, not_unique)
  4253. int x, level, good, not_unique;
  4254. {
  4255.     register inven_type *t_ptr;
  4256.     register int32u      chance, special, cursed, i;
  4257.     int32u               tmp;
  4258.  
  4259.     chance = OBJ_BASE_MAGIC + level;
  4260.     if (chance > OBJ_BASE_MAX)
  4261.     chance = OBJ_BASE_MAX;
  4262.     special = chance / OBJ_DIV_SPECIAL;
  4263.     cursed = (10 * chance) / OBJ_DIV_CURSED;
  4264.     t_ptr = &t_list[x];
  4265.  
  4266. /*
  4267.  * some objects appear multiple times in the object_list with different
  4268.  * levels, this is to make the object occur more often, however, for
  4269.  * consistency, must set the level of these duplicates to be the same as the
  4270.  * object with the lowest level 
  4271.  */
  4272.  
  4273. /* Depending on treasure type, it can have certain magical properties */
  4274.     switch (t_ptr->tval) {
  4275.       case TV_SHIELD:
  4276.       case TV_HARD_ARMOR:
  4277.       case TV_SOFT_ARMOR:
  4278.     if ((t_ptr->index >= 389 && t_ptr->index <= 394)
  4279.         || (t_ptr->index >= 408 && t_ptr->index <= 409)
  4280.         || (t_ptr->index >= 415 && t_ptr->index <= 419)) {
  4281.  
  4282.         int8u               artifact = FALSE;
  4283.  
  4284.     /* all DSM are enchanted, I guess -CFT */
  4285.         t_ptr->toac += m_bonus(0, 5, level) + randint(5);
  4286.         rating += 30;
  4287.         if ((magik(chance) && magik(special)) || (good == 666)) {
  4288.         t_ptr->toac += randint(5);    /* even better... */
  4289.         if ((randint(3) == 1 || good == 666) && !not_unique
  4290.             && unique_armour(t_ptr))    /* ...but is it an artifact? */
  4291.             artifact = TRUE;
  4292.         }
  4293.         if (!artifact) {       /* assume cost&mesg done if it was an
  4294.                     * artifact */
  4295.         if (wizard || peek)
  4296.             msg_print("Dragon Scale Mail");
  4297.         t_ptr->cost += ((int32) t_ptr->toac * 500L);
  4298.         }
  4299.     }
  4300.      /* end if is a DSM */ 
  4301.     else if (magik(chance) || good) {
  4302.         t_ptr->toac += randint(3) + m_bonus(0, 5, level);
  4303.         if (!stricmp(object_list[t_ptr->index].name, "& Robe") &&
  4304.         ((magik(special) && randint(30) == 1)
  4305.          || (good == 666 && magik(special)))) {
  4306.         t_ptr->flags |= (TR_RES_LIGHT | TR_RES_COLD | TR_RES_ACID |
  4307.                  TR_RES_FIRE | TR_SUST_STAT);
  4308.         if (wizard || peek)
  4309.             msg_print("Robe of the Magi");
  4310.         rating += 30;
  4311.         t_ptr->flags2 |= TR_HOLD_LIFE;
  4312.         t_ptr->ident |= ID_NOSHOW_P1;
  4313.         give_1_hi_resist(t_ptr);    /* JLS */
  4314.         t_ptr->p1 = 10;
  4315.         t_ptr->toac += 10 + randint(5);
  4316.         t_ptr->name2 = SN_MAGI;
  4317.         t_ptr->cost = 10000L + (t_ptr->toac * 100);
  4318.         } else if (magik(special) || good == 666)
  4319.         switch (randint(9)) {
  4320.           case 1:
  4321.             if ((randint(3) == 1 || good == 666) && !not_unique &&
  4322.             unique_armour(t_ptr))
  4323.             break;
  4324.             t_ptr->flags |= (TR_RES_LIGHT | TR_RES_COLD | TR_RES_ACID |
  4325.                      TR_RES_FIRE);
  4326.             if (randint(3) == 1) {
  4327.             if (peek)
  4328.                 msg_print("Elvenkind");
  4329.             rating += 25;
  4330.             give_1_hi_resist(t_ptr);    /* JLS */
  4331.             t_ptr->flags |= TR_STEALTH;
  4332.             t_ptr->p1 = randint(3);
  4333.             t_ptr->name2 = SN_ELVENKIND;
  4334.             t_ptr->toac += 15;
  4335.             t_ptr->cost += 15000L;
  4336.             } else {
  4337.             if (peek)
  4338.                 msg_print("Resist");
  4339.             rating += 20;
  4340.             t_ptr->name2 = SN_R;
  4341.             t_ptr->toac += 8;
  4342.             t_ptr->cost += 12500L;
  4343.             }
  4344.             break;
  4345.           case 2:       /* Resist Acid      */
  4346.             if ((randint(3) == 1 || good == 666) && !not_unique &&
  4347.             unique_armour(t_ptr))
  4348.             break;
  4349.             if (!strncmp(object_list[t_ptr->index].name,
  4350.                  "Mithril", 7) ||
  4351.             !strncmp(object_list[t_ptr->index].name,
  4352.                  "Adamantite", 10))
  4353.             break;
  4354.             if (peek)
  4355.             msg_print("Resist Acid");
  4356.             rating += 15;
  4357.             t_ptr->flags |= TR_RES_ACID;
  4358.             t_ptr->name2 = SN_RA;
  4359.             t_ptr->cost += 1000L;
  4360.             break;
  4361.           case 3:
  4362.           case 4:       /* Resist Fire      */
  4363.             if ((randint(3) == 1 || good == 666) && !not_unique &&
  4364.             unique_armour(t_ptr))
  4365.             break;
  4366.             if (peek)
  4367.             msg_print("Resist Fire");
  4368.             rating += 17;
  4369.             t_ptr->flags |= TR_RES_FIRE;
  4370.             t_ptr->name2 = SN_RF;
  4371.             t_ptr->cost += 600L;
  4372.             break;
  4373.           case 5:
  4374.           case 6:       /* Resist Cold     */
  4375.             if ((randint(3) == 1 || good == 666) && !not_unique &&
  4376.             unique_armour(t_ptr))
  4377.             break;
  4378.             if (peek)
  4379.             msg_print("Resist Cold");
  4380.             rating += 16;
  4381.             t_ptr->flags |= TR_RES_COLD;
  4382.             t_ptr->name2 = SN_RC;
  4383.             t_ptr->cost += 600L;
  4384.             break;
  4385.           case 7:
  4386.           case 8:
  4387.           case 9:       /* Resist Lightning */
  4388.             if ((randint(3) == 1 || good == 666) && !not_unique &&
  4389.             unique_armour(t_ptr))
  4390.             break;
  4391.             if (peek)
  4392.             msg_print("Resist Lightning");
  4393.             rating += 15;
  4394.             t_ptr->flags |= TR_RES_LIGHT;
  4395.             t_ptr->name2 = SN_RL;
  4396.             t_ptr->cost += 500L;
  4397.             break;
  4398.         }
  4399.     } else if (magik(cursed)) {
  4400.         t_ptr->toac = -randint(3) - m_bonus(0, 10, level);
  4401.         t_ptr->cost = 0L;
  4402.         t_ptr->flags |= TR_CURSED;
  4403.     }
  4404.     break;
  4405.  
  4406.       case TV_HAFTED:
  4407.       case TV_POLEARM:
  4408.       case TV_SWORD:
  4409.     /* always show tohit/todam values if identified */
  4410.     t_ptr->ident |= ID_SHOW_HITDAM;
  4411.     if (magik(chance) || good) {
  4412.         t_ptr->tohit += randint(3) + m_bonus(0, 10, level);
  4413.         t_ptr->todam += randint(3) + m_bonus(0, 10, level);
  4414.     /*
  4415.      * the 3*special/2 is needed because weapons are not as common as
  4416.      * before change to treasure distribution, this helps keep same
  4417.      * number of ego weapons same as before, see also missiles 
  4418.      */
  4419.         if (magik(3*special/2)||good==666) { /* was 2 */
  4420.         if (!stricmp("& Whip", object_list[t_ptr->index].name)
  4421.             && randint(2)==1) {
  4422.             if (peek) msg_print("Whip of Fire");
  4423.             rating += 20;
  4424.             t_ptr->name2 = SN_FIRE;
  4425.             t_ptr->flags |= (TR_FLAME_TONGUE | TR_RES_FIRE);
  4426.             /* this should allow some WICKED whips -CFT */
  4427.             while (randint(5*(int)t_ptr->damage[0])==1) {
  4428.             t_ptr->damage[0]++;
  4429.             t_ptr->cost += 2500;
  4430.             t_ptr->cost *= 2;
  4431.             }
  4432.             t_ptr->tohit += 5;
  4433.             t_ptr->todam += 5;
  4434.         } else {
  4435.             switch (randint(30)) {    /* was 16 */
  4436.               case 1:       /* Holy Avenger     */
  4437.             if (((randint(2) == 1) || (good == 666))
  4438.                 && !not_unique &&
  4439.                 unique_weapon(t_ptr))
  4440.                 break;
  4441.             if (peek)
  4442.                 msg_print("Holy Avenger");
  4443.             rating += 30;
  4444.             t_ptr->flags |= (TR_SEE_INVIS | TR_SUST_STAT |
  4445.                       TR_SLAY_UNDEAD | TR_SLAY_EVIL | TR_WIS);
  4446.             t_ptr->flags2 |= (TR_SLAY_DEMON | TR_BLESS_BLADE);
  4447.             t_ptr->tohit += 5;
  4448.             t_ptr->todam += 5;
  4449.             t_ptr->toac += randint(4);
  4450.             /* the value in p1 is used for strength increase */
  4451.             /* p1 is also used for sustain stat */
  4452.             t_ptr->p1 = randint(4);
  4453.             t_ptr->name2 = SN_HA;
  4454.             t_ptr->cost += t_ptr->p1 * 500;
  4455.             t_ptr->cost += 10000L;
  4456.             t_ptr->cost *= 2;
  4457.             break;
  4458.               case 2:       /* Defender     */
  4459.             if (((randint(2) == 1) || (good == 666)) && !not_unique &&
  4460.                 unique_weapon(t_ptr))
  4461.                 break;
  4462.             if (peek)
  4463.                 msg_print("Defender");
  4464.             rating += 23;
  4465.             t_ptr->flags |= (TR_FFALL | TR_RES_LIGHT | TR_SEE_INVIS
  4466.                    | TR_FREE_ACT | TR_RES_COLD | TR_RES_ACID
  4467.                      | TR_RES_FIRE | TR_REGEN | TR_STEALTH);
  4468.             t_ptr->tohit += 3;
  4469.             t_ptr->todam += 3;
  4470.             t_ptr->toac += 5 + randint(5);
  4471.             t_ptr->name2 = SN_DF;
  4472.             /* the value in p1 is used for stealth */
  4473.             t_ptr->p1 = randint(3);
  4474.             t_ptr->cost += t_ptr->p1 * 500;
  4475.             t_ptr->cost += 7500L;
  4476.             t_ptr->cost *= 2;
  4477.             break;
  4478.               case 3:
  4479.               case 4:       /* Flame Tongue  */
  4480.             if (((randint(2) == 1) || (good == 666)) && !not_unique &&
  4481.                 unique_weapon(t_ptr))
  4482.                 break;
  4483.             rating += 20;
  4484.             t_ptr->flags |= (TR_FLAME_TONGUE | TR_RES_FIRE);
  4485.             if (peek)
  4486.                 msg_print("Flame");
  4487.             t_ptr->tohit += 2;
  4488.             t_ptr->todam += 3;
  4489.             t_ptr->name2 = SN_FT;
  4490.             t_ptr->cost += 3000L;
  4491.             break;
  4492.               case 5:
  4493.               case 6:       /* Frost Brand   */
  4494.             if (((randint(2) == 1) || (good == 666)) && !not_unique &&
  4495.                 unique_weapon(t_ptr))
  4496.                 break;
  4497.             if (peek)
  4498.                 msg_print("Frost");
  4499.             rating += 20;
  4500.             t_ptr->flags |= (TR_FROST_BRAND | TR_RES_COLD);
  4501.             t_ptr->tohit += 2;
  4502.             t_ptr->todam += 2;
  4503.             t_ptr->name2 = SN_FB;
  4504.             t_ptr->cost += 2200L;
  4505.             break;
  4506.               case 7:
  4507.               case 8:       /* Slay Animal  */
  4508.             t_ptr->flags |= TR_SLAY_ANIMAL;
  4509.             rating += 15;
  4510.             if (peek)
  4511.                 msg_print("Slay Animal");
  4512.             t_ptr->tohit += 3;
  4513.             t_ptr->todam += 3;
  4514.             t_ptr->name2 = SN_SA;
  4515.             t_ptr->cost += 2000L;
  4516.             break;
  4517.               case 9:
  4518.               case 10:       /* Slay Dragon     */
  4519.             t_ptr->flags |= TR_SLAY_DRAGON;
  4520.             if (peek)
  4521.                 msg_print("Slay Dragon");
  4522.             rating += 18;
  4523.             t_ptr->tohit += 3;
  4524.             t_ptr->todam += 3;
  4525.             t_ptr->name2 = SN_SD;
  4526.             t_ptr->cost += 4000L;
  4527.             break;
  4528.               case 11:
  4529.               case 12:       /* Slay Evil   */
  4530.             t_ptr->flags |= TR_SLAY_EVIL;
  4531.             if (randint(3) == 1) {
  4532.                 t_ptr->flags |= (TR_WIS);
  4533.                 t_ptr->flags2 |= (TR_BLESS_BLADE);
  4534.                 t_ptr->p1 = m_bonus(0, 3, level);
  4535.                 t_ptr->cost += (200 * t_ptr->p1);
  4536.             }
  4537.             if (peek)
  4538.                 msg_print("Slay Evil");
  4539.             rating += 18;
  4540.             t_ptr->tohit += 3;
  4541.             t_ptr->todam += 3;
  4542.             t_ptr->name2 = SN_SE;
  4543.             t_ptr->cost += 4000L;
  4544.             break;
  4545.               case 13:
  4546.               case 14:       /* Slay Undead      */
  4547.             t_ptr->flags |= (TR_SEE_INVIS | TR_SLAY_UNDEAD);
  4548.             if (randint(3) == 1) {
  4549.                 t_ptr->flags2 |= (TR_HOLD_LIFE);
  4550.                 t_ptr->cost += 1000;
  4551.             }
  4552.             if (peek)
  4553.                 msg_print("Slay Undead");
  4554.             rating += 18;
  4555.             t_ptr->tohit += 2;
  4556.             t_ptr->todam += 2;
  4557.             t_ptr->name2 = SN_SU;
  4558.             t_ptr->cost += 3000L;
  4559.             break;
  4560.               case 15:
  4561.               case 16:
  4562.               case 17:       /* Slay Orc */
  4563.             t_ptr->flags2 |= TR_SLAY_ORC;
  4564.             if (peek)
  4565.                 msg_print("Slay Orc");
  4566.             rating += 13;
  4567.             t_ptr->tohit += 2;
  4568.             t_ptr->todam += 2;
  4569.             t_ptr->name2 = SN_SO;
  4570.             t_ptr->cost += 1200L;
  4571.             break;
  4572.               case 18:
  4573.               case 19:
  4574.               case 20:       /* Slay Troll */
  4575.             t_ptr->flags2 |= TR_SLAY_TROLL;
  4576.             if (peek)
  4577.                 msg_print("Slay Troll");
  4578.             rating += 13;
  4579.             t_ptr->tohit += 2;
  4580.             t_ptr->todam += 2;
  4581.             t_ptr->name2 = SN_ST;
  4582.             t_ptr->cost += 1200L;
  4583.             break;
  4584.               case 21:
  4585.               case 22:
  4586.               case 23:
  4587.             t_ptr->flags2 |= TR_SLAY_GIANT;
  4588.             if (peek)
  4589.                 msg_print("Slay Giant");
  4590.             rating += 14;
  4591.             t_ptr->tohit += 2;
  4592.             t_ptr->todam += 2;
  4593.             t_ptr->name2 = SN_SG;
  4594.             t_ptr->cost += 1200L;
  4595.             break;
  4596.               case 24:
  4597.               case 25:
  4598.               case 26:
  4599.             t_ptr->flags2 |= TR_SLAY_DEMON;
  4600.             if (peek)
  4601.                 msg_print("Slay Demon");
  4602.             rating += 16;
  4603.             t_ptr->tohit += 2;
  4604.             t_ptr->todam += 2;
  4605.             t_ptr->name2 = SN_SDEM;
  4606.             t_ptr->cost += 1200L;
  4607.             break;
  4608.               case 27:       /* of Westernesse */
  4609.             if (((randint(2) == 1) || (good == 666)) && !not_unique &&
  4610.                 unique_weapon(t_ptr))
  4611.                 break;
  4612.             if (peek)
  4613.                 msg_print("Westernesse");
  4614.             rating += 20;
  4615.             t_ptr->flags |= (TR_SEE_INVIS | TR_DEX | TR_CON | TR_STR |
  4616.                      TR_FREE_ACT);
  4617.             t_ptr->flags2 |= TR_SLAY_ORC;
  4618.             t_ptr->tohit += randint(5) + 3;
  4619.             t_ptr->todam += randint(5) + 3;
  4620.             t_ptr->p1 = 1;
  4621.             t_ptr->cost += 10000L;
  4622.             t_ptr->cost *= 2;
  4623.             t_ptr->name2 = SN_WEST;
  4624.             break;
  4625.               case 28:
  4626.               case 29:       /* Blessed Blade -DGK */
  4627.             if ((t_ptr->tval != TV_SWORD) &&
  4628.                 (t_ptr->tval != TV_POLEARM))
  4629.                 break;
  4630.             if (peek)
  4631.                 msg_print("Blessed");
  4632.             rating += 20;
  4633.             t_ptr->flags = TR_WIS;
  4634.             t_ptr->flags2 = TR_BLESS_BLADE;
  4635.             t_ptr->tohit += 3;
  4636.             t_ptr->todam += 3;
  4637.             t_ptr->p1 = randint(3);
  4638.             t_ptr->name2 = SN_BLESS_BLADE;
  4639.             t_ptr->cost += t_ptr->p1 * 1000;
  4640.             t_ptr->cost += 3000L;
  4641.             break;
  4642.               case 30:       /* of Speed -DGK */
  4643.             if (((randint(2) == 1) || (good == 666))
  4644.                 && !not_unique && unique_weapon(t_ptr))
  4645.                 break;
  4646.             if (wizard || peek)
  4647.                 msg_print("Weapon of Extra Attacks");
  4648.             rating += 20;
  4649.             t_ptr->tohit += randint(5);
  4650.             t_ptr->todam += randint(3);
  4651.             t_ptr->flags2 = TR_ATTACK_SPD;
  4652.             if (t_ptr->weight <= 80)
  4653.                 t_ptr->p1 = randint(3);
  4654.             else if (t_ptr->weight <= 130)
  4655.                 t_ptr->p1 = randint(2);
  4656.             else
  4657.                 t_ptr->p1 = 1;
  4658.             t_ptr->name2 = SN_ATTACKS;
  4659.             t_ptr->cost += (t_ptr->p1 * 2000);
  4660.             t_ptr->cost *= 2;
  4661.             break;
  4662.             }
  4663.         }
  4664.         }
  4665.     } else if (magik(cursed)) {
  4666.         t_ptr->tohit = (-randint(3) - m_bonus(1, 20, level));
  4667.         t_ptr->todam = (-randint(3) - m_bonus(1, 20, level));
  4668.         t_ptr->flags |= TR_CURSED;
  4669.         if (level > (20 + randint(15)) && randint(10) == 1) {
  4670.         t_ptr->name2 = SN_MORGUL;
  4671.         t_ptr->flags |= (TR_SEE_INVIS | TR_AGGRAVATE);
  4672.         t_ptr->tohit -= 15;
  4673.         t_ptr->todam -= 15;
  4674.         t_ptr->toac = -10;
  4675.         t_ptr->weight += 100;
  4676.         }
  4677.         t_ptr->cost = 0L;
  4678.     }
  4679.     break;
  4680.       case TV_BOW:
  4681.     /* always show tohit/todam values if identified */
  4682.     t_ptr->ident |= ID_SHOW_HITDAM;
  4683.     if (magik(chance) || good) {
  4684.         t_ptr->tohit = randint(3) + m_bonus(0, 10, level);
  4685.         t_ptr->todam = randint(3) + m_bonus(0, 10, level);
  4686.         switch (randint(15)) {
  4687.           case 1: case 2: case 3:
  4688.         if (((randint(3)==1)||(good==666)) && !not_unique &&
  4689.             !stricmp(object_list[t_ptr->index].name, "& Long Bow") &&
  4690.             (((i=randint(2))==1 && !BELEG) || (i==2 && !BARD))) {
  4691.             switch (i) {
  4692.             case 1:
  4693.               if (BELEG)
  4694.                 break;
  4695.             if (wizard || peek)
  4696.                 msg_print("Belthronding");
  4697.             else
  4698.                 good_item_flag = TRUE;
  4699.             t_ptr->name2 = SN_BELEG;
  4700.             t_ptr->ident |= ID_NOSHOW_TYPE;
  4701.             t_ptr->subval = 4; /* make do x5 damage!! -CFT */
  4702.             t_ptr->tohit = 20;
  4703.             t_ptr->todam = 22;
  4704.             t_ptr->p1 = 3;
  4705.             t_ptr->flags |= (TR_STEALTH | TR_DEX);
  4706.             t_ptr->flags2 |= (TR_ARTIFACT | TR_RES_DISENCHANT);
  4707.             t_ptr->cost = 35000L;
  4708.             BELEG = 1;
  4709.             break;
  4710.               case 2:
  4711.             if (BARD)
  4712.                 break;
  4713.             if (wizard || peek)
  4714.                 msg_print("Bard");
  4715.             else
  4716.                 good_item_flag = TRUE;
  4717.             t_ptr->name2 = SN_BARD;
  4718.             t_ptr->subval = 3; /* make do x4 damage!! -CFT */
  4719.             t_ptr->tohit = 17;
  4720.             t_ptr->todam = 19;
  4721.             t_ptr->p1 = 3;
  4722.             t_ptr->flags |= (TR_FREE_ACT | TR_DEX);
  4723.             t_ptr->flags2 |= (TR_ARTIFACT);
  4724.             t_ptr->cost = 20000L;
  4725.             BARD = 1;
  4726.             break;
  4727.             }
  4728.             break;
  4729.         }
  4730.         if (((randint(5) == 1) || (good == 666)) && !not_unique &&
  4731.             !stricmp(object_list[t_ptr->index].name, "& Light Crossbow")
  4732.             && !CUBRAGOL) {
  4733.             if (CUBRAGOL)
  4734.             break;
  4735.             if (wizard || peek)
  4736.             msg_print("Cubragol");
  4737.             t_ptr->name2 = SN_CUBRAGOL;
  4738.             t_ptr->subval = 11;
  4739.             t_ptr->tohit = 10;
  4740.             t_ptr->todam = 14;
  4741.             t_ptr->p1 = 1;
  4742.             t_ptr->flags |= (TR_SPEED | TR_RES_FIRE);
  4743.             t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  4744.             t_ptr->cost = 38000L;
  4745.             CUBRAGOL = 1;
  4746.             break;
  4747.         }
  4748.         t_ptr->name2 = SN_MIGHT;
  4749.         if (peek)
  4750.             msg_print("Bow of Might");
  4751.         rating += 15;
  4752.         t_ptr->subval++; /* make it do an extra multiple of damage */
  4753.         t_ptr->tohit += 5;
  4754.         t_ptr->todam += 10;
  4755.         break;
  4756.           case 4: case 5: case 6: case 7: case 8:
  4757.         t_ptr->name2 = SN_MIGHT;
  4758.         if (peek) msg_print("Bow of Might");
  4759.         rating += 11;
  4760.         t_ptr->tohit += 5;
  4761.         t_ptr->todam += 12;
  4762.         break;
  4763.  
  4764.           case 9: case 10: case 11: case 12:
  4765.           case 13: case 14: case 15:
  4766.         t_ptr->name2 = SN_ACCURACY;
  4767.         rating += 11;
  4768.         if (peek)
  4769.             msg_print("Accuracy");
  4770.         t_ptr->tohit += 12;
  4771.         t_ptr->todam += 5;
  4772.         break;
  4773.         }
  4774.     } else if (magik(cursed)) {
  4775.         t_ptr->tohit = (-m_bonus(5, 30, level));
  4776.         t_ptr->todam = (-m_bonus(5, 20, level));    /* add damage. -CJS- */
  4777.         t_ptr->flags |= TR_CURSED;
  4778.         t_ptr->cost = 0L;
  4779.     }
  4780.     break;
  4781.  
  4782.       case TV_DIGGING:
  4783.     /* always show tohit/todam values if identified */
  4784.     t_ptr->ident |= ID_SHOW_HITDAM;
  4785.     if (magik(chance) || (good == 666)) {
  4786.         tmp = randint(3);
  4787.         if (tmp == 1) {
  4788.         t_ptr->p1 += m_bonus(0, 5, level);
  4789.         }
  4790.         if (tmp == 2)    /* do not give additional plusses -CWS */
  4791.         ;
  4792.         else {
  4793.         /* a cursed digging tool */
  4794.         t_ptr->p1 = (-m_bonus(1, 15, level));
  4795.         t_ptr->cost = 0L;
  4796.         t_ptr->flags |= TR_CURSED;
  4797.         }
  4798.     }
  4799.     break;
  4800.  
  4801.       case TV_GLOVES:
  4802.     if (magik(chance) || good) {
  4803.         t_ptr->toac = randint(3) + m_bonus(0, 10, level);
  4804.         if ((((randint(2) == 1) && magik(5 * special / 2)) || (good == 666)) &&
  4805.         !stricmp(object_list[t_ptr->index].name,
  4806.              "& Set of Leather Gloves") &&
  4807.         !not_unique && unique_armour(t_ptr));
  4808.         else if ((((randint(4) == 1) && magik(special)) || (good == 666))
  4809.              && !stricmp(object_list[t_ptr->index].name,
  4810.                  "& Set of Gauntlets") &&
  4811.              !not_unique && unique_armour(t_ptr));
  4812.         else if ((((randint(5) == 1) && magik(special)) || (good == 666))
  4813.              && !stricmp(object_list[t_ptr->index].name,
  4814.                  "& Set of Cesti") &&
  4815.              !not_unique && unique_armour(t_ptr));
  4816.     /* don't forget cesti -CFT */
  4817.         else if (magik(special) || (good == 666)) {
  4818.         switch (randint(10)) {
  4819.           case 1:
  4820.           case 2:
  4821.           case 3:
  4822.             if (peek)
  4823.             msg_print("Free action");
  4824.             rating += 11;
  4825.             t_ptr->flags |= TR_FREE_ACT;
  4826.             t_ptr->name2 = SN_FREE_ACTION;
  4827.             t_ptr->cost += 1000L;
  4828.             break;
  4829.           case 4:
  4830.           case 5:
  4831.           case 6:
  4832.             t_ptr->ident |= ID_SHOW_HITDAM;
  4833.             rating += 17;
  4834.             if (peek)
  4835.             msg_print("Slaying");
  4836.             t_ptr->tohit += 1 + randint(4);
  4837.             t_ptr->todam += 1 + randint(4);
  4838.             t_ptr->name2 = SN_SLAYING;
  4839.             t_ptr->cost += (t_ptr->tohit + t_ptr->todam) * 250;
  4840.             break;
  4841.           case 7:
  4842.           case 8:
  4843.           case 9:
  4844.             t_ptr->name2 = SN_AGILITY;
  4845.             if (peek)
  4846.             msg_print("Agility");
  4847.             rating += 14;
  4848.             t_ptr->p1 = 2 + randint(2);
  4849.             t_ptr->flags |= TR_DEX;
  4850.             t_ptr->cost += (t_ptr->p1) * 400;
  4851.             break;
  4852.           case 10:
  4853.             if (((randint(3) == 1) || (good == 666)) && !not_unique &&
  4854.             unique_armour(t_ptr))
  4855.             break;
  4856.             if (peek)
  4857.             msg_print("Power");
  4858.             rating += 22;
  4859.             t_ptr->name2 = SN_POWER;
  4860.             t_ptr->p1 = 1 + randint(4);
  4861.             t_ptr->tohit += 1 + randint(4);
  4862.             t_ptr->todam += 1 + randint(4);
  4863.             t_ptr->flags |= TR_STR;
  4864.             t_ptr->ident |= ID_SHOW_HITDAM;
  4865.             t_ptr->ident |= ID_NOSHOW_TYPE;
  4866.             t_ptr->cost += (t_ptr->tohit + t_ptr->todam + t_ptr->p1) * 300;
  4867.             break;
  4868.         }
  4869.         }
  4870.     } else if (magik(cursed)) {
  4871.         if (magik(special)) {
  4872.         if (randint(2) == 1) {
  4873.             t_ptr->flags |= TR_DEX;
  4874.             t_ptr->name2 = SN_CLUMSINESS;
  4875.         } else {
  4876.             t_ptr->flags |= TR_STR;
  4877.             t_ptr->name2 = SN_WEAKNESS;
  4878.         }
  4879.         t_ptr->p1 = (randint(3) - m_bonus(0, 10, level));
  4880.         }
  4881.         t_ptr->toac = (-m_bonus(1, 20, level));
  4882.         t_ptr->flags |= TR_CURSED;
  4883.         t_ptr->cost = 0;
  4884.     }
  4885.     break;
  4886.  
  4887.       case TV_BOOTS:
  4888.     if (magik(chance) || good) {
  4889.         t_ptr->toac = randint(3) + m_bonus(1, 10, level);
  4890.         if (magik(special) || (good == 666)) {
  4891.         tmp = randint(12);
  4892.         if (tmp == 1) {
  4893.             if (!((randint(2) == 1) && !not_unique
  4894.               && unique_armour(t_ptr))) {
  4895.             t_ptr->flags |= TR_SPEED;
  4896.             if (wizard || peek)
  4897.                 msg_print("Boots of Speed");
  4898.             t_ptr->name2 = SN_SPEED;
  4899.             rating += 30;
  4900.             t_ptr->p1 = 1;
  4901.             t_ptr->cost += 300000L;
  4902.             }
  4903.         } else if (stricmp("& Pair of Metal Shod Boots",
  4904.                    object_list[t_ptr->index].name))    /* not metal */
  4905.             if (tmp > 6) {
  4906.             t_ptr->flags |= TR_FFALL;
  4907.             rating += 7;
  4908.             t_ptr->name2 = SN_SLOW_DESCENT;
  4909.             t_ptr->cost += 250;
  4910.             } else if (tmp < 5) {
  4911.             t_ptr->flags |= TR_STEALTH;
  4912.             rating += 16;
  4913.             t_ptr->p1 = randint(3);
  4914.             t_ptr->name2 = SN_STEALTH;
  4915.             t_ptr->cost += 500;
  4916.             } else {       /* 5,6 */
  4917.             t_ptr->flags |= TR_FREE_ACT;
  4918.             rating += 15;
  4919.             t_ptr->name2 = SN_FREE_ACTION;
  4920.             t_ptr->cost += 500;
  4921.             t_ptr->cost *= 2;
  4922.             }
  4923.         else
  4924.          /* is metal boots, different odds since no stealth */
  4925.             if (tmp < 5) {
  4926.             t_ptr->flags |= TR_FREE_ACT;
  4927.             rating += 15;
  4928.             t_ptr->name2 = SN_FREE_ACTION;
  4929.             t_ptr->cost += 500;
  4930.             t_ptr->cost *= 2;
  4931.             } else {       /* tmp > 4 */
  4932.             t_ptr->flags |= TR_FFALL;
  4933.             rating += 7;
  4934.             t_ptr->name2 = SN_SLOW_DESCENT;
  4935.             t_ptr->cost += 250;
  4936.             }
  4937.         }
  4938.     } else if (magik(cursed)) {
  4939.         tmp = randint(3);
  4940.         if (tmp == 1) {
  4941.         t_ptr->flags |= TR_SPEED;
  4942.         t_ptr->name2 = SN_SLOWNESS;
  4943.         t_ptr->p1 = -1;
  4944.         } else if (tmp == 2) {
  4945.         t_ptr->flags |= TR_AGGRAVATE;
  4946.         t_ptr->name2 = SN_NOISE;
  4947.         } else {
  4948.         t_ptr->name2 = SN_GREAT_MASS;
  4949.         t_ptr->weight = t_ptr->weight * 5;
  4950.         }
  4951.         t_ptr->cost = 0;
  4952.         t_ptr->toac = (-m_bonus(2, 20, level));
  4953.         t_ptr->flags |= TR_CURSED;
  4954.     }
  4955.     break;
  4956.  
  4957.       case TV_HELM:           /* Helms */
  4958.     if ((t_ptr->subval >= 6) && (t_ptr->subval <= 8)) {
  4959.     /* give crowns a higher chance for magic */
  4960.         chance += t_ptr->cost / 100;
  4961.         special += special;
  4962.     }
  4963.     if (magik(chance) || good) {
  4964.         t_ptr->toac = randint(3) + m_bonus(0, 10, level);
  4965.         if (magik(special) || (good == 666)) {
  4966.         if (t_ptr->subval < 6) {
  4967.             tmp = randint(14);
  4968.             if (tmp < 3) {
  4969.             if (!((randint(2) == 1) && !not_unique &&
  4970.                   unique_armour(t_ptr))) {
  4971.                 if (peek)
  4972.                 msg_print("Intelligence");
  4973.                 t_ptr->p1 = randint(2);
  4974.                 rating += 13;
  4975.                 t_ptr->flags |= TR_INT;
  4976.                 t_ptr->name2 = SN_INTELLIGENCE;
  4977.                 t_ptr->cost += t_ptr->p1 * 500;
  4978.             }
  4979.             } else if (tmp < 6) {
  4980.             if (!((randint(2) == 1) && !not_unique &&
  4981.                   unique_armour(t_ptr))) {
  4982.                 if (peek)
  4983.                 msg_print("Wisdom");
  4984.                 rating += 13;
  4985.                 t_ptr->p1 = randint(2);
  4986.                 t_ptr->flags |= TR_WIS;
  4987.                 t_ptr->name2 = SN_WISDOM;
  4988.                 t_ptr->cost += t_ptr->p1 * 500;
  4989.             }
  4990.             } else if (tmp < 10) {
  4991.             if (!((randint(2) == 1) && !not_unique &&
  4992.                   unique_armour(t_ptr))) {
  4993.                 t_ptr->p1 = 1 + randint(4);
  4994.                 rating += 11;
  4995.                 t_ptr->flags |= TR_INFRA;
  4996.                 t_ptr->name2 = SN_INFRAVISION;
  4997.                 t_ptr->cost += t_ptr->p1 * 250;
  4998.             }
  4999.             } else if (tmp < 12) {
  5000.             if (!((randint(2) == 1) && !not_unique &&
  5001.                   unique_armour(t_ptr))) {
  5002.                 if (peek)
  5003.                 msg_print("Light");
  5004.                 t_ptr->flags2 |= (TR_RES_LT | TR_LIGHT);
  5005.                 rating += 6;
  5006.                 t_ptr->name2 = SN_LIGHT;
  5007.                 t_ptr->cost += 500;
  5008.             }
  5009.             } else if (tmp < 14) {
  5010.             if (!((randint(2) == 1) && !not_unique &&
  5011.                   unique_armour(t_ptr))) {
  5012.                 if (peek)
  5013.                 msg_print("Helm of Seeing");
  5014.                 t_ptr->flags |= TR_SEE_INVIS;
  5015.                 t_ptr->flags2 |= TR_RES_BLIND;
  5016.                 rating += 8;
  5017.                 t_ptr->name2 = SN_SEEING;
  5018.                 t_ptr->cost += 1000;
  5019.             }
  5020.             } else {
  5021.             if (!((randint(2) == 1) && !not_unique &&
  5022.                   unique_armour(t_ptr))) {
  5023.                 if (peek)
  5024.                 msg_print("Telepathy");
  5025.                 rating += 20;
  5026.                 t_ptr->flags2 |= TR_TELEPATHY;
  5027.                 t_ptr->name2 = SN_TELEPATHY;
  5028.                 t_ptr->cost += 50000L;
  5029.             }
  5030.             }
  5031.         } else {
  5032.             switch (randint(6)) {
  5033.               case 1:
  5034.             if (!(((randint(2) == 1) || (good == 666)) &&
  5035.                   !not_unique && unique_armour(t_ptr))) {
  5036.                 if (peek)
  5037.                 msg_print("Crown of Might");
  5038.                 rating += 19;
  5039.                 t_ptr->p1 = randint(3);
  5040.                 t_ptr->flags |= (TR_FREE_ACT | TR_CON |
  5041.                          TR_DEX | TR_STR);
  5042.                 t_ptr->name2 = SN_MIGHT;
  5043.                 t_ptr->cost += 1000 + t_ptr->p1 * 500;
  5044.             }
  5045.             break;
  5046.               case 2:
  5047.             if (peek)
  5048.                 msg_print("Lordliness");
  5049.             t_ptr->p1 = randint(3);
  5050.             rating += 17;
  5051.             t_ptr->flags |= (TR_CHR | TR_WIS);
  5052.             t_ptr->name2 = SN_LORDLINESS;
  5053.             t_ptr->cost += 1000 + t_ptr->p1 * 500;
  5054.             break;
  5055.               case 3:
  5056.             if (peek)
  5057.                 msg_print("Crown of the Magi");
  5058.             rating += 15;
  5059.             t_ptr->p1 = randint(3);
  5060.             t_ptr->flags |= (TR_RES_LIGHT | TR_RES_COLD
  5061.                       | TR_RES_ACID | TR_RES_FIRE | TR_INT);
  5062.             t_ptr->name2 = SN_MAGI;
  5063.             t_ptr->cost += 3000 + t_ptr->p1 * 500;
  5064.             break;
  5065.               case 4:
  5066.             rating += 8;
  5067.             if (peek)
  5068.                 msg_print("Beauty");
  5069.             t_ptr->p1 = randint(4);
  5070.             t_ptr->flags |= TR_CHR;
  5071.             t_ptr->name2 = SN_BEAUTY;
  5072.             t_ptr->cost += 750;
  5073.             break;
  5074.               case 5:
  5075.             if (peek)
  5076.                 msg_print("Seeing");
  5077.             rating += 8;
  5078.             t_ptr->p1 = 5 * (1 + randint(4));
  5079.             t_ptr->flags |= (TR_SEE_INVIS | TR_SEARCH);
  5080.             t_ptr->name2 = SN_SEEING;
  5081.             t_ptr->cost += 1000 + t_ptr->p1 * 100;
  5082.             break;
  5083.               case 6:
  5084.             t_ptr->flags |= TR_REGEN;
  5085.             rating += 10;
  5086.             if (peek)
  5087.                 msg_print("Regeneration");
  5088.             t_ptr->name2 = SN_REGENERATION;
  5089.             t_ptr->cost += 1500;
  5090.             break;
  5091.  
  5092.             }
  5093.         }
  5094.         }
  5095.     } else if (magik(cursed)) {
  5096.         t_ptr->toac -= m_bonus(1, 20, level);
  5097.         t_ptr->flags |= TR_CURSED;
  5098.         t_ptr->cost = 0;
  5099.         if (magik(special))
  5100.         switch (randint(7)) {
  5101.           case 1:
  5102.             t_ptr->p1 = -randint(5);
  5103.             t_ptr->flags |= TR_INT;
  5104.             t_ptr->name2 = SN_STUPIDITY;
  5105.             break;
  5106.           case 2:
  5107.           case 3:
  5108.             t_ptr->p1 = -randint(5);
  5109.             t_ptr->flags |= TR_WIS;
  5110.             t_ptr->name2 = SN_DULLNESS;
  5111.             break;
  5112.           case 4:
  5113.           case 5:
  5114.             t_ptr->p1 = -randint(5);
  5115.             t_ptr->flags |= TR_STR;
  5116.             t_ptr->name2 = SN_WEAKNESS;
  5117.             break;
  5118.           case 6:
  5119.             t_ptr->flags |= TR_TELEPORT;
  5120.             t_ptr->name2 = SN_TELEPORTATION;
  5121.             break;
  5122.           case 7:
  5123.             t_ptr->p1 = -randint(5);
  5124.             t_ptr->flags |= TR_CHR;
  5125.             t_ptr->name2 = SN_UGLINESS;
  5126.             break;
  5127.         }
  5128.     }
  5129.     break;
  5130.  
  5131.       case TV_RING:           /* Rings          */
  5132.     if (!((randint(10) == 1) && !not_unique && unique_armour(t_ptr))) {
  5133.         switch (t_ptr->subval) {
  5134.           case 0:
  5135.           case 1:
  5136.           case 2:
  5137.           case 3:           /* 132-135 */
  5138.         if (magik(cursed)) {
  5139.             t_ptr->p1 = -m_bonus(1, 10, level);
  5140.             t_ptr->flags |= TR_CURSED;
  5141.             t_ptr->cost = -t_ptr->cost;
  5142.         } else {
  5143.             t_ptr->p1 = m_bonus(1, 6, level);
  5144.             t_ptr->cost += t_ptr->p1 * 100;
  5145.         }
  5146.         break;
  5147.           case 4:           /* 136 */
  5148.         if (magik(cursed)) {
  5149.             t_ptr->p1 = -randint(3);
  5150.             t_ptr->flags |= TR_CURSED;
  5151.             t_ptr->cost = -t_ptr->cost;
  5152.         } else {
  5153.             if (peek)
  5154.             msg_print("Ring of Speed");
  5155.             rating += 35;
  5156.             if (randint(888) == 1)
  5157.             t_ptr->p1 = 2;
  5158.             else
  5159.             t_ptr->p1 = 1;
  5160.         }
  5161.         break;
  5162.           case 5:
  5163.         t_ptr->p1 = 5 * m_bonus(1, 10, level);
  5164.         t_ptr->cost += t_ptr->p1 * 30;
  5165.         if (magik(cursed)) {
  5166.             t_ptr->p1 = -t_ptr->p1;
  5167.             t_ptr->flags |= TR_CURSED;
  5168.             t_ptr->cost = -t_ptr->cost;
  5169.         }
  5170.         break;
  5171.           case 14:
  5172.           case 15:
  5173.           case 16:           /* Flames, Acid, Ice */
  5174.         t_ptr->toac = m_bonus(1, 10, level);
  5175.         t_ptr->toac += 5 + randint(7);
  5176.         t_ptr->cost += t_ptr->toac * 100;
  5177.         break;
  5178.               case 17:
  5179.               case 18:           /* WOE, Stupidity */
  5180.         t_ptr->toac = (-5) - m_bonus(1,10,level);
  5181.         t_ptr->p1 = (-randint(4));
  5182.         break;
  5183.           case 19:           /* Increase damage          */
  5184.         t_ptr->todam = m_bonus(1, 10, level);
  5185.         t_ptr->todam += 3 + randint(10);
  5186.         t_ptr->cost += t_ptr->todam * 100;
  5187.         if (magik(cursed)) {
  5188.             t_ptr->todam = -t_ptr->todam;
  5189.             t_ptr->flags |= TR_CURSED;
  5190.             t_ptr->cost = -t_ptr->cost;
  5191.         }
  5192.         break;
  5193.           case 20:           /* Increase To-Hit          */
  5194.         t_ptr->tohit = m_bonus(1, 10, level);
  5195.         t_ptr->tohit += 3 + randint(10);
  5196.         t_ptr->cost += t_ptr->tohit * 100;
  5197.         if (magik(cursed)) {
  5198.             t_ptr->tohit = -t_ptr->tohit;
  5199.             t_ptr->flags |= TR_CURSED;
  5200.             t_ptr->cost = -t_ptr->cost;
  5201.         }
  5202.         break;
  5203.           case 21:           /* Protection          */
  5204.         t_ptr->toac = m_bonus(0, 10, level);
  5205.         t_ptr->toac += 4 + randint(5);
  5206.         t_ptr->cost += t_ptr->toac * 100;
  5207.         if (magik(cursed)) {
  5208.             t_ptr->toac = -t_ptr->toac;
  5209.             t_ptr->flags |= TR_CURSED;
  5210.             t_ptr->cost = -t_ptr->cost;
  5211.         }
  5212.         break;
  5213.           case 24:
  5214.           case 25:
  5215.           case 26:
  5216.           case 27:
  5217.           case 28:
  5218.           case 29:
  5219.         t_ptr->ident |= ID_NOSHOW_P1;
  5220.         break;
  5221.           case 30:           /* Slaying          */
  5222.         t_ptr->ident |= ID_SHOW_HITDAM;
  5223.         t_ptr->todam = m_bonus(1, 10, level);
  5224.         t_ptr->todam += 2 + randint(3);
  5225.         t_ptr->tohit = m_bonus(1, 10, level);
  5226.         t_ptr->tohit += 2 + randint(3);
  5227.         t_ptr->cost += (t_ptr->tohit + t_ptr->todam) * 100;
  5228.         if (magik(cursed)) {
  5229.             t_ptr->tohit = -t_ptr->tohit;
  5230.             t_ptr->todam = -t_ptr->todam;
  5231.             t_ptr->flags |= TR_CURSED;
  5232.             t_ptr->cost = -t_ptr->cost;
  5233.         }
  5234.         break;
  5235.           default:
  5236.         break;
  5237.         }
  5238.     }
  5239.     break;
  5240.  
  5241.       case TV_AMULET:           /* Amulets          */
  5242.     if (t_ptr->subval < 2) {
  5243.         if (magik(cursed)) {
  5244.         t_ptr->p1 = -m_bonus(1, 5, level);
  5245.         t_ptr->flags |= TR_CURSED;
  5246.         t_ptr->cost = -t_ptr->cost;
  5247.         } else {
  5248.         t_ptr->p1 = m_bonus(1, 5, level);
  5249.         t_ptr->cost += t_ptr->p1 * 100;
  5250.         }
  5251.     } else if (t_ptr->subval == 2) { /* searching */
  5252.         t_ptr->p1 = 5 * (randint(3) + m_bonus(0, 8, level));
  5253.         if (magik(cursed)) {
  5254.         t_ptr->p1 = -t_ptr->p1;
  5255.         t_ptr->cost = -t_ptr->cost;
  5256.         t_ptr->flags |= TR_CURSED;
  5257.         } else
  5258.         t_ptr->cost += 20 * t_ptr->p1;
  5259.     } else if (t_ptr->subval == 8) {
  5260.         rating += 25;
  5261.         t_ptr->p1 = 5 * (randint(2) + m_bonus(0, 10, level));
  5262.         t_ptr->toac = randint(4) + m_bonus(0, 8, level) - 2;
  5263.         t_ptr->cost += 20 * t_ptr->p1 + 50 * t_ptr->toac;
  5264.         if (t_ptr->toac < 0) /* sort-of cursed...just to be annoying -CWS */
  5265.         t_ptr->flags |= TR_CURSED;
  5266.     } else if (t_ptr->subval == 9) {
  5267.     /* amulet of DOOM */
  5268.         t_ptr->p1 = (-randint(5) - m_bonus(2, 10, level));
  5269.         t_ptr->toac = (-randint(3) - m_bonus(0, 6, level));
  5270.         t_ptr->flags |= TR_CURSED;
  5271.     }
  5272.     break;
  5273.  
  5274.     /* Subval should be even for store, odd for dungeon */
  5275.     /* Dungeon found ones will be partially charged     */
  5276.       case TV_LIGHT:
  5277.     if ((t_ptr->subval % 2) == 1) {
  5278.         t_ptr->p1 = randint(t_ptr->p1);
  5279.         t_ptr->subval -= 1;
  5280.     }
  5281.     break;
  5282.  
  5283.       case TV_WAND:
  5284.     switch (t_ptr->subval) {
  5285.       case 0:
  5286.         t_ptr->p1 = randint(10) + 6;
  5287.         break;
  5288.       case 1:
  5289.         t_ptr->p1 = randint(8) + 6;
  5290.         break;
  5291.       case 2:
  5292.         t_ptr->p1 = randint(5) + 6;
  5293.         break;
  5294.       case 3:
  5295.         t_ptr->p1 = randint(8) + 6;
  5296.         break;
  5297.       case 4:
  5298.         t_ptr->p1 = randint(4) + 3;
  5299.         break;
  5300.       case 5:
  5301.         t_ptr->p1 = randint(8) + 6;
  5302.         break;
  5303.       case 6:
  5304.         t_ptr->p1 = randint(20) + 12;
  5305.         break;
  5306.       case 7:
  5307.         t_ptr->p1 = randint(20) + 12;
  5308.         break;
  5309.       case 8:
  5310.         t_ptr->p1 = randint(10) + 6;
  5311.         break;
  5312.       case 9:
  5313.         t_ptr->p1 = randint(12) + 6;
  5314.         break;
  5315.       case 10:
  5316.         t_ptr->p1 = randint(10) + 12;
  5317.         break;
  5318.       case 11:
  5319.         t_ptr->p1 = randint(3) + 3;
  5320.         break;
  5321.       case 12:
  5322.         t_ptr->p1 = randint(8) + 6;
  5323.         break;
  5324.       case 13:
  5325.         t_ptr->p1 = randint(10) + 6;
  5326.         break;
  5327.       case 14:
  5328.         t_ptr->p1 = randint(5) + 3;
  5329.         break;
  5330.       case 15:
  5331.         t_ptr->p1 = randint(5) + 3;
  5332.         break;
  5333.       case 16:
  5334.         t_ptr->p1 = randint(5) + 6;
  5335.         break;
  5336.       case 17:
  5337.         t_ptr->p1 = randint(5) + 4;
  5338.         break;
  5339.       case 18:
  5340.         t_ptr->p1 = randint(8) + 4;
  5341.         break;
  5342.       case 19:
  5343.         t_ptr->p1 = randint(6) + 2;
  5344.         break;
  5345.       case 20:
  5346.         t_ptr->p1 = randint(4) + 2;
  5347.         break;
  5348.       case 21:
  5349.         t_ptr->p1 = randint(8) + 6;
  5350.         break;
  5351.       case 22:
  5352.         t_ptr->p1 = randint(5) + 2;
  5353.         break;
  5354.       case 23:
  5355.         t_ptr->p1 = randint(12) + 12;
  5356.         break;
  5357.       case 24:
  5358.         t_ptr->p1 = randint(3) + 1;
  5359.         break;
  5360.       case 25:
  5361.         t_ptr->p1 = randint(3) + 1;
  5362.         break;
  5363.       case 26:
  5364.         t_ptr->p1 = randint(3) + 1;
  5365.         break;
  5366.       case 27:
  5367.         t_ptr->p1 = randint(2) + 1;
  5368.         break;
  5369.       case 28:
  5370.         t_ptr->p1 = randint(8) + 6;
  5371.         break;
  5372.       default:
  5373.         break;
  5374.     }
  5375.     break;
  5376.  
  5377.       case TV_STAFF:
  5378.     switch (t_ptr->subval) {
  5379.       case 0:
  5380.         t_ptr->p1 = randint(20) + 12;
  5381.         break;
  5382.       case 1:
  5383.         t_ptr->p1 = randint(8) + 6;
  5384.         break;
  5385.       case 2:
  5386.         t_ptr->p1 = randint(5) + 6;
  5387.         break;
  5388.       case 3:
  5389.         t_ptr->p1 = randint(20) + 12;
  5390.         break;
  5391.       case 4:
  5392.         t_ptr->p1 = randint(15) + 6;
  5393.         break;
  5394.       case 5:
  5395.         t_ptr->p1 = randint(4) + 5;
  5396.         break;
  5397.       case 6:
  5398.         t_ptr->p1 = randint(5) + 3;
  5399.         break;
  5400.       case 7:
  5401.         t_ptr->p1 = randint(3) + 1;
  5402.         t_ptr->level = 10;
  5403.         break;
  5404.       case 8:
  5405.         t_ptr->p1 = randint(3) + 1;
  5406.         break;
  5407.       case 9:
  5408.         t_ptr->p1 = randint(5) + 6;
  5409.         break;
  5410.       case 10:
  5411.         t_ptr->p1 = randint(10) + 12;
  5412.         break;
  5413.       case 11:
  5414.         t_ptr->p1 = randint(5) + 6;
  5415.         break;
  5416.       case 12:
  5417.         t_ptr->p1 = randint(5) + 6;
  5418.         break;
  5419.       case 13:
  5420.         t_ptr->p1 = randint(5) + 6;
  5421.         break;
  5422.       case 14:
  5423.         t_ptr->p1 = randint(10) + 12;
  5424.         break;
  5425.       case 15:
  5426.         t_ptr->p1 = randint(3) + 4;
  5427.         break;
  5428.       case 16:
  5429.         t_ptr->p1 = randint(5) + 6;
  5430.         break;
  5431.       case 17:
  5432.         t_ptr->p1 = randint(5) + 6;
  5433.         break;
  5434.       case 18:
  5435.         t_ptr->p1 = randint(3) + 4;
  5436.         break;
  5437.       case 19:
  5438.         t_ptr->p1 = randint(10) + 12;
  5439.         break;
  5440.       case 20:
  5441.         t_ptr->p1 = randint(3) + 4;
  5442.         break;
  5443.       case 21:
  5444.         t_ptr->p1 = randint(3) + 4;
  5445.         break;
  5446.       case 22:
  5447.         t_ptr->p1 = randint(10) + 6;
  5448.         t_ptr->level = 5;
  5449.         break;
  5450.       case 23:
  5451.         t_ptr->p1 = randint(2) + 1;
  5452.         break;
  5453.       case 24:
  5454.         t_ptr->p1 = randint(3) + 1;
  5455.         break;
  5456.       case 25:
  5457.         t_ptr->p1 = randint(2) + 2;
  5458.         break;
  5459.       case 26:
  5460.         t_ptr->p1 = randint(15) + 5;
  5461.         break;
  5462.       case 27:
  5463.         t_ptr->p1 = randint(2) + 2;
  5464.         break;
  5465.       case 28:
  5466.         t_ptr->p1 = randint(5) + 5;
  5467.         break;
  5468.       case 29:
  5469.         t_ptr->p1 = randint(2) + 1;
  5470.         break;
  5471.       case 30:
  5472.         t_ptr->p1 = randint(6) + 2;
  5473.         break;
  5474.       default:
  5475.         break;
  5476.     }
  5477.     break;
  5478.  
  5479.       case TV_CLOAK:
  5480.     if (magik(chance) || good) {
  5481.         int                 made_art_cloak;
  5482.  
  5483.         made_art_cloak = 0;
  5484.         t_ptr->toac += 1 + m_bonus(0, 20, level);
  5485.         if (magik(special) || (good == 666)) {
  5486.         if (!not_unique &&
  5487.             !stricmp(object_list[t_ptr->index].name, "& Cloak")
  5488.             && randint(10) == 1) {
  5489.             switch (randint(9)) {
  5490.               case 1:
  5491.               case 2:
  5492.             if (COLLUIN)
  5493.                 break;
  5494.             if (wizard || peek)
  5495.                 msg_print("Colluin");
  5496.             else
  5497.                 good_item_flag = TRUE;
  5498.             t_ptr->name2 = SN_COLLUIN;
  5499.             t_ptr->toac = 15;
  5500.             t_ptr->flags |= (TR_RES_FIRE | TR_RES_COLD | TR_POISON |
  5501.                      TR_RES_LIGHT | TR_RES_ACID);
  5502.             t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  5503.             t_ptr->cost = 10000L;
  5504.             made_art_cloak = 1;
  5505.             COLLUIN = 1;
  5506.             break;
  5507.               case 3:
  5508.               case 4:
  5509.             if (HOLCOLLETH)
  5510.                 break;
  5511.             if (wizard || peek)
  5512.                 msg_print("Holcolleth");
  5513.             else
  5514.                 good_item_flag = TRUE;
  5515.             t_ptr->name2 = SN_HOLCOLLETH;
  5516.             t_ptr->toac = 4;
  5517.             t_ptr->p1 = 2;
  5518.             t_ptr->flags |= (TR_INT | TR_WIS | TR_STEALTH |
  5519.                      TR_RES_ACID);
  5520.             t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  5521.             t_ptr->ident |= ID_NOSHOW_TYPE;
  5522.             t_ptr->cost = 13000L;
  5523.             made_art_cloak = 1;
  5524.             HOLCOLLETH = 1;
  5525.             break;
  5526.               case 5:
  5527.             if (THINGOL)
  5528.                 break;
  5529.             if (wizard || peek)
  5530.                 msg_print("Thingol");
  5531.             else
  5532.                 good_item_flag = TRUE;
  5533.             t_ptr->name2 = SN_THINGOL;
  5534.             t_ptr->toac = 18;
  5535.             t_ptr->flags = (TR_DEX | TR_CHR | TR_RES_FIRE |
  5536.                    TR_RES_ACID | TR_RES_COLD | TR_FREE_ACT);
  5537.             t_ptr->flags2 = (TR_ACTIVATE | TR_ARTIFACT);
  5538.             t_ptr->p1 = 3;
  5539.             t_ptr->cost = 35000L;
  5540.             made_art_cloak = 1;
  5541.             THINGOL = 1;
  5542.             break;
  5543.               case 6:
  5544.               case 7:
  5545.             if (THORONGIL)
  5546.                 break;
  5547.             if (wizard || peek)
  5548.                 msg_print("Thorongil");
  5549.             else
  5550.                 good_item_flag = TRUE;
  5551.             t_ptr->name2 = SN_THORONGIL;
  5552.             t_ptr->toac = 10;
  5553.             t_ptr->flags = (TR_SEE_INVIS | TR_FREE_ACT |
  5554.                     TR_RES_ACID);
  5555.             t_ptr->flags2 |= (TR_ARTIFACT);
  5556.             t_ptr->cost = 8000L;
  5557.             made_art_cloak = 1;
  5558.             THORONGIL = 1;
  5559.             break;
  5560.               case 8:
  5561.               case 9:
  5562.             if (COLANNON)
  5563.                 break;
  5564.             if (wizard || peek)
  5565.                 msg_print("Colannon");
  5566.             else
  5567.                 good_item_flag = TRUE;
  5568.             t_ptr->name2 = SN_COLANNON;
  5569.             t_ptr->toac = 15;
  5570.             t_ptr->flags |= (TR_STEALTH | TR_RES_ACID);
  5571.             t_ptr->flags2 |= (TR_ACTIVATE | TR_ARTIFACT);
  5572.             t_ptr->p1 = 3;
  5573.             t_ptr->cost = 11000L;
  5574.             made_art_cloak = 1;
  5575.             COLANNON = 1;
  5576.             break;
  5577.             }
  5578.  
  5579.         } else if (!not_unique &&
  5580.                !stricmp(object_list[t_ptr->index].name,
  5581.                     "& Shadow Cloak")
  5582.                && randint(20) == 1) {
  5583.             switch (randint(2)) {
  5584.               case 1:
  5585.             if (LUTHIEN)
  5586.                 break;
  5587.             if (wizard || peek)
  5588.                 msg_print("Luthien");
  5589.             else
  5590.                 good_item_flag = TRUE;
  5591.             t_ptr->name2 = SN_LUTHIEN;
  5592.             t_ptr->toac = 20;
  5593.             t_ptr->flags = (TR_RES_FIRE | TR_RES_COLD |
  5594.                     TR_INT | TR_WIS | TR_CHR | TR_RES_ACID);
  5595.             t_ptr->flags2 = (TR_ACTIVATE | TR_ARTIFACT);
  5596.             t_ptr->p1 = 2;
  5597.             t_ptr->cost = 45000L;
  5598.             made_art_cloak = 1;
  5599.             LUTHIEN = 1;
  5600.             break;
  5601.               case 2:
  5602.             if (TUOR)
  5603.                 break;
  5604.             if (wizard || peek)
  5605.                 msg_print("Tuor");
  5606.             else
  5607.                 good_item_flag = TRUE;
  5608.             t_ptr->name2 = SN_TUOR;
  5609.             t_ptr->toac = 12;
  5610.             t_ptr->flags = (TR_STEALTH |
  5611.                   TR_FREE_ACT | TR_SEE_INVIS | TR_RES_ACID);
  5612.             t_ptr->flags2 |= (TR_IM_ACID | TR_ARTIFACT);
  5613.             t_ptr->p1 = 4;
  5614.             t_ptr->cost = 35000L;
  5615.             made_art_cloak = 1;
  5616.             TUOR = 1;
  5617.             break;
  5618.             }
  5619.         }
  5620.         if (!made_art_cloak) {
  5621.             if (randint(2) == 1) {
  5622.             t_ptr->name2 = SN_PROTECTION;
  5623.             t_ptr->toac += m_bonus(0, 10, level) + (5 + randint(3));
  5624.             t_ptr->cost += 250L;
  5625.             rating += 8;
  5626.             } else if (randint(10) < 10) {
  5627.             t_ptr->toac += m_bonus(3, 10, level);
  5628.             t_ptr->p1 = randint(3);
  5629.             t_ptr->flags |= TR_STEALTH;
  5630.             t_ptr->name2 = SN_STEALTH;
  5631.             t_ptr->cost += 500 + (50 * t_ptr->p1);
  5632.             rating += 9;
  5633.             } else {
  5634.             t_ptr->toac += 10 + randint(10);
  5635.             t_ptr->p1 = randint(3);
  5636.             t_ptr->flags |= (TR_STEALTH | TR_RES_ACID);
  5637.             t_ptr->name2 = SN_AMAN;
  5638.             t_ptr->cost += 4000 + (100 * t_ptr->toac);
  5639.             rating += 16;
  5640.             }
  5641.         }
  5642.         }
  5643.     } else if (magik(cursed)) {
  5644.         tmp = randint(3);
  5645.         if (tmp == 1) {
  5646.         t_ptr->flags |= TR_AGGRAVATE;
  5647.         t_ptr->name2 = SN_IRRITATION;
  5648.         t_ptr->toac -= m_bonus(1, 10, level);
  5649.         t_ptr->ident |= ID_SHOW_HITDAM;
  5650.         t_ptr->tohit -= m_bonus(1, 10, level);
  5651.         t_ptr->todam -= m_bonus(1, 10, level);
  5652.         t_ptr->cost = 0;
  5653.         } else if (tmp == 2) {
  5654.         t_ptr->name2 = SN_VULNERABILITY;
  5655.         t_ptr->toac -= m_bonus(10, 20, level + 50);
  5656.         t_ptr->cost = 0;
  5657.         } else {
  5658.         t_ptr->name2 = SN_ENVELOPING;
  5659.         t_ptr->toac -= m_bonus(1, 10, level);
  5660.         t_ptr->ident |= ID_SHOW_HITDAM;
  5661.         t_ptr->tohit -= m_bonus(2, 15, level + 10);
  5662.         t_ptr->todam -= m_bonus(2, 15, level + 10);
  5663.         t_ptr->cost = 0;
  5664.         }
  5665.         t_ptr->flags |= TR_CURSED;
  5666.     }
  5667.     break;
  5668.  
  5669.       case TV_CHEST:
  5670.     switch (randint(level + 4)) {
  5671.       case 1:
  5672.         t_ptr->flags = 0;
  5673.         t_ptr->name2 = SN_EMPTY;
  5674.         break;
  5675.       case 2:
  5676.         t_ptr->flags |= CH_LOCKED;
  5677.         t_ptr->name2 = SN_LOCKED;
  5678.         break;
  5679.       case 3:
  5680.       case 4:
  5681.         t_ptr->flags |= (CH_LOSE_STR | CH_LOCKED);
  5682.         t_ptr->name2 = SN_POISON_NEEDLE;
  5683.         break;
  5684.       case 5:
  5685.       case 6:
  5686.         t_ptr->flags |= (CH_POISON | CH_LOCKED);
  5687.         t_ptr->name2 = SN_POISON_NEEDLE;
  5688.         break;
  5689.       case 7:
  5690.       case 8:
  5691.       case 9:
  5692.         t_ptr->flags |= (CH_PARALYSED | CH_LOCKED);
  5693.         t_ptr->name2 = SN_GAS_TRAP;
  5694.         break;
  5695.       case 10:
  5696.       case 11:
  5697.         t_ptr->flags |= (CH_EXPLODE | CH_LOCKED);
  5698.         t_ptr->name2 = SN_EXPLOSION_DEVICE;
  5699.         break;
  5700.       case 12:
  5701.       case 13:
  5702.       case 14:
  5703.         t_ptr->flags |= (CH_SUMMON | CH_LOCKED);
  5704.         t_ptr->name2 = SN_SUMMONING_RUNES;
  5705.         break;
  5706.       case 15:
  5707.       case 16:
  5708.       case 17:
  5709.         t_ptr->flags |= (CH_PARALYSED | CH_POISON | CH_LOSE_STR |
  5710.                  CH_LOCKED);
  5711.         t_ptr->name2 = SN_MULTIPLE_TRAPS;
  5712.         break;
  5713.       default:
  5714.         t_ptr->flags |= (CH_SUMMON | CH_EXPLODE | CH_LOCKED);
  5715.         t_ptr->name2 = SN_MULTIPLE_TRAPS;
  5716.         break;
  5717.     }
  5718.     if (not_unique)        /* if bought from store - dbd */
  5719.         t_ptr->p1 = randint(t_ptr->level);
  5720.     else            /* store the level chest's found on - dbd */
  5721.         t_ptr->p1 = dun_level;
  5722.     break;
  5723.  
  5724.       case TV_SPIKE:
  5725.     t_ptr->number = 0;
  5726.     for (i = 0; i < 7; i++)
  5727.         t_ptr->number += randint(6);
  5728.     if (missile_ctr == MAX_SHORT)
  5729.         missile_ctr = -MAX_SHORT - 1;
  5730.     else
  5731.         missile_ctr++;
  5732.     t_ptr->p1 = missile_ctr;
  5733.     break;
  5734.  
  5735.     case TV_BOLT: case TV_ARROW: case TV_SLING_AMMO:
  5736.      /* this fn makes ammo for player's missile weapon more common -CFT */
  5737.       magic_ammo(t_ptr, good, chance, special, cursed, level);
  5738.       break;
  5739.  
  5740.       case TV_FOOD:
  5741.     /* make sure all food rations have the same level */
  5742.     if (t_ptr->subval == 90)
  5743.         t_ptr->level = 0;
  5744.     /* give all elvish waybread the same level */
  5745.     else if (t_ptr->subval == 92)
  5746.         t_ptr->level = 6;
  5747.     break;
  5748.  
  5749.       case TV_SCROLL1:
  5750.     /* give all identify scrolls the same level */
  5751.     if (t_ptr->subval == 67)
  5752.         t_ptr->level = 1;
  5753.     /* scroll of light */
  5754.     else if (t_ptr->subval == 69)
  5755.         t_ptr->level = 0;
  5756.     /* scroll of trap detection */
  5757.     else if (t_ptr->subval == 80)
  5758.         t_ptr->level = 5;
  5759.     /* scroll of door/stair location */
  5760.     else if (t_ptr->subval == 81)
  5761.         t_ptr->level = 5;
  5762.     break;
  5763.  
  5764.       case TV_POTION1:           /* potions */
  5765.     /* cure light */
  5766.     if (t_ptr->subval == 76)
  5767.         t_ptr->level = 0;
  5768.     break;
  5769.  
  5770.       default:
  5771.     break;
  5772.     }
  5773. }
  5774.  
  5775.  
  5776. static struct opt_desc {
  5777.     const char         *o_prompt;
  5778.     int                *o_var;
  5779. } options[] = {
  5780.  
  5781.     { "Running: cut known corners",         &find_cut },
  5782.     { "Running: examine potential corners",    &find_examine },
  5783.     { "Running: print self during run",     &find_prself },
  5784.     { "Running: stop when map sector changes",  &find_bound},
  5785.     { "Running: run through open doors",     &find_ignore_doors},
  5786.     { "(g)et-key to pickup objects",         &prompt_carry_flag},
  5787.     { "Prompt before pickup",             &carry_query_flag},
  5788.     { "Rogue like commands",             &rogue_like_commands},
  5789.     { "Show weights in inventory",         &show_weight_flag},
  5790.     { "Show weights in equipment list",        &show_equip_weight_flag},
  5791.     { "Highlight and notice mineral seams",     &highlight_seams},
  5792.     { "Disable haggling in stores",        &no_haggle_flag},
  5793.     { "Plain object descriptions",        &plain_descriptions},
  5794.     { "Quick messages",                        &quick_messages},
  5795.     { "Equippy chars",                        &equippy_chars},
  5796.     { "Low hitpoint warning",            &hitpoint_warn},
  5797.     { "Delay speed",                 &delay_spd},
  5798.     { (char *)0,                 (int *)0}
  5799. };
  5800.  
  5801.  
  5802. /* Set or unset various boolean options.        -CJS- */
  5803. void 
  5804. set_options()
  5805. {
  5806.     register int i, max, ch;
  5807.     vtype        string;
  5808.  
  5809.     prt("  ESC when finished, y/n or 0-9 to set options, <return> or - to move cursor",
  5810.     0, 0);
  5811.     for (max = 0; options[max].o_prompt != 0; max++) {
  5812.     if (options[max].o_var == &hitpoint_warn)
  5813.         (void)sprintf(string, "%-38s: %d0%% ", options[max].o_prompt,
  5814.               *options[max].o_var);
  5815.     else if (options[max].o_var == &delay_spd)
  5816.         (void)sprintf(string, "%-38s: %d ", options[max].o_prompt,
  5817.               *options[max].o_var);
  5818.     else
  5819.         (void)sprintf(string, "%-38s: %s ", options[max].o_prompt,
  5820.               (*options[max].o_var ? "yes" : "no "));
  5821.     prt(string, max + 1, 0);
  5822.     }
  5823.     erase_line(max + 1, 0);
  5824.     i = 0;
  5825.     for (;;) {
  5826.     move_cursor(i + 1, 40);
  5827.     ch = inkey();
  5828.     switch (ch) {
  5829.       case ESCAPE:      
  5830.         draw_cave();
  5831.         creatures(FALSE);     /* draw monsters */
  5832.         prt_equippy_chars(); /* redraw equippy chars */
  5833.         return;
  5834.       case '-':
  5835.         if (i > 0)
  5836.         i--;
  5837.         else
  5838.         i = max - 1;
  5839.         break;
  5840.       case ' ':
  5841.       case '\n':
  5842.       case '\r':
  5843.         if (i + 1 < max)
  5844.         i++;
  5845.         else
  5846.         i = 0;
  5847.         break;
  5848.       case 'y':
  5849.       case 'Y':
  5850.         if ((options[i].o_var == &hitpoint_warn) ||
  5851.         (options[i].o_var == &delay_spd))
  5852.         bell();
  5853.         else {
  5854.         put_buffer("yes ", i + 1, 40);
  5855.         *options[i].o_var = TRUE;
  5856.         if (i + 1 < max)
  5857.             i++;
  5858.         else
  5859.             i = 0;
  5860.         }
  5861.         break;
  5862.       case 'n':
  5863.       case 'N':
  5864.         if (options[i].o_var == &delay_spd)
  5865.         bell();
  5866.         else if (options[i].o_var == &hitpoint_warn) {
  5867.         put_buffer("00%", i + 1, 40);
  5868.         *options[i].o_var = 0;
  5869.         } else {
  5870.         put_buffer("no  ", i + 1, 40);
  5871.         *options[i].o_var = FALSE;
  5872.         if (i + 1 < max)
  5873.             i++;
  5874.         else
  5875.             i = 0;
  5876.         }
  5877.         break;
  5878.       case '1':
  5879.       case '2':
  5880.       case '3':
  5881.       case '4':
  5882.       case '5':
  5883.       case '6':
  5884.       case '7':
  5885.       case '8':
  5886.       case '9':
  5887.       case '0':
  5888.         if ((options[i].o_var != &delay_spd) &&
  5889.         (options[i].o_var != &hitpoint_warn))
  5890.         bell();
  5891.         else {
  5892.         ch = ch - '0';
  5893.         *options[i].o_var = ch;
  5894.         if (options[i].o_var == &hitpoint_warn)
  5895.             sprintf(string, "%d0%%  ", ch);
  5896.         else
  5897.             sprintf(string, "%d   ", ch);
  5898.         put_buffer(string, i + 1, 40);
  5899.         if (i + 1 < max)
  5900.             i++;
  5901.         else
  5902.             i = 0;
  5903.         }
  5904.         break;
  5905.       default:
  5906.         bell();
  5907.         break;
  5908.     }
  5909.     }
  5910. }
  5911.  
  5912. static void
  5913. magic_ammo(t_ptr, good, chance, special, cursed, level)
  5914. inven_type *t_ptr;
  5915. int         good, chance, special, cursed, level;
  5916. {
  5917.     register inven_type *i_ptr = NULL;
  5918.     register int         i;
  5919.  
  5920.     /* if wielding a bow as main/aux weapon, then ammo will be "right" ammo
  5921.      * more often than not of the time -CFT */
  5922.     if (inventory[INVEN_WIELD].tval == TV_BOW) i_ptr=&inventory[INVEN_WIELD];
  5923.     else if (inventory[INVEN_AUX].tval == TV_BOW) i_ptr=&inventory[INVEN_AUX];
  5924.  
  5925.     if (i_ptr && (randint(2)==1)){
  5926.     if ((t_ptr->tval == TV_SLING_AMMO) &&
  5927.         (i_ptr->subval >= 20) && (i_ptr->subval <= 21));
  5928.     /* right type, do nothing */
  5929.     else if ((t_ptr->tval == TV_ARROW) &&
  5930.          (i_ptr->subval >= 1) && (i_ptr->subval <= 4));
  5931.     /* right type, do nothing */
  5932.     else if ((t_ptr->tval == TV_BOLT) &&
  5933.          (i_ptr->subval >= 10) && (i_ptr->subval <= 12));
  5934.     /* right type, do nothing */
  5935.     else if ((i_ptr->subval >= 20) && (i_ptr->subval <= 21))
  5936.         invcopy(t_ptr, 83); /* this should be treasure list index of shots -CFT */
  5937.     else if ((i_ptr->subval >= 1) && (i_ptr->subval <= 4))
  5938.         invcopy(t_ptr, 78); /* this should be index of arrows -CFT */
  5939.     else            /* xbow */
  5940.         invcopy(t_ptr, 80); /* this should be index of bolts -CFT */
  5941.     }
  5942.  
  5943.     t_ptr->number = 0;
  5944.     for (i = 0; i < 7; i++)
  5945.     t_ptr->number += randint(6);
  5946.     if (missile_ctr == MAX_SHORT)
  5947.     missile_ctr = -MAX_SHORT - 1;
  5948.     else
  5949.     missile_ctr++;
  5950.     t_ptr->p1 = missile_ctr;
  5951.  
  5952.     /* always show tohit/todam values if identified */
  5953.     t_ptr->ident |= ID_SHOW_HITDAM;
  5954.     if (magik(chance)||good) {
  5955.     t_ptr->tohit = randint(5) + m_bonus(1, 15, level);
  5956.     t_ptr->todam = randint(5) + m_bonus(1, 15, level);
  5957.     /* see comment for weapons */
  5958.     if (magik(5*special/2)||(good==666))
  5959.         switch(randint(11)) {
  5960.           case 1: case 2: case 3:
  5961.         t_ptr->name2 = SN_WOUNDING; /* swapped with slaying -CFT */
  5962.         t_ptr->tohit += 5;
  5963.         t_ptr->todam += 5;
  5964.         t_ptr->damage[0] ++; /* added -CFT */
  5965.         t_ptr->cost += 30;
  5966.         rating += 5;
  5967.         break;
  5968.           case 4: case 5:
  5969.         t_ptr->flags |= (TR_FLAME_TONGUE|TR_RES_FIRE); /* RF so won't burn */
  5970.         t_ptr->tohit += 2;
  5971.         t_ptr->todam += 4;
  5972.         t_ptr->name2 = SN_FIRE;
  5973.         t_ptr->cost += 25;
  5974.         rating += 6;
  5975.         break;
  5976.           case 6: case 7:
  5977.         t_ptr->flags |= TR_SLAY_EVIL;
  5978.         t_ptr->tohit += 3;
  5979.         t_ptr->todam += 3;
  5980.         t_ptr->name2 = SN_SLAY_EVIL;
  5981.         t_ptr->cost += 25;
  5982.         rating += 7;
  5983.         break;
  5984.           case 8: case 9:
  5985.         t_ptr->flags |= TR_SLAY_ANIMAL;
  5986.         t_ptr->tohit += 2;
  5987.         t_ptr->todam += 2;
  5988.         t_ptr->name2 = SN_SLAY_ANIMAL;
  5989.         t_ptr->cost += 30;
  5990.         rating += 5;
  5991.         break;
  5992.           case 10:
  5993.         t_ptr->flags |= TR_SLAY_DRAGON;
  5994.         t_ptr->tohit += 3;
  5995.         t_ptr->todam += 3;
  5996.         t_ptr->name2 = SN_DRAGON_SLAYING;
  5997.         t_ptr->cost += 35;
  5998.         rating += 9;
  5999.         break;
  6000.           case 11:
  6001.         t_ptr->tohit += 10; /* reduced because of dice bonus -CFT */
  6002.         t_ptr->todam += 10;
  6003.         t_ptr->name2 = SN_SLAYING; /* swapped w/ wounding -CFT */
  6004.         t_ptr->damage[0] += 2; /* added -CFT */
  6005.         t_ptr->cost += 45;
  6006.         rating += 10;
  6007.         break;
  6008.         }
  6009.     while (magik(special)) { /* added -CFT */
  6010.         t_ptr->damage[0]++;
  6011.         t_ptr->cost += t_ptr->damage[0]*5;
  6012.     }
  6013.     }
  6014.     else if (magik(cursed)) {
  6015.     t_ptr->tohit = (-randint(10)) - m_bonus(5, 25, level);
  6016.     t_ptr->todam = (-randint(10)) - m_bonus(5, 25, level);
  6017.     t_ptr->flags |= TR_CURSED;
  6018.     t_ptr->cost = 0;
  6019.     if (randint(5)==1) {
  6020.         t_ptr->name2 = SN_BACKBITING;
  6021.         t_ptr->tohit -= 20;
  6022.         t_ptr->todam -= 20;
  6023.     }
  6024.     }
  6025. }
  6026.